library(data.table)
library(fixest)
library(lmtest)
library(memisc)
library(multcomp)
library(multiwayvcov)
library(survey)

# set working directory to location where replication archive is stored
setwd("")

# read in data for Study 1 (conjoint)
study1_responses <- fread("Study1_Final.csv", header = TRUE, stringsAsFactors = FALSE)

# set baseline levels for each attribute-level
study1_responses$temp <- relevel(as.factor(study1_responses$temp), 
                                  ref = "64")
study1_responses$attractions <- relevel(as.factor(study1_responses$attractions), 
                                         ref = "Amusement parks")
study1_responses$traveltime <- relevel(as.factor(study1_responses$traveltime), 
                                        ref = "Less than 2 hours")
study1_responses$preselec <- relevel(as.factor(study1_responses$preselec), 
                                      ref = "Donald Trump won by a large margin")
study1_responses$recentnews <- relevel(as.factor(study1_responses$recentnews), 
                                        ref = "State legislature formed a commission to study ways to stimulate economic growth")
study1_responses$community <- relevel(as.factor(study1_responses$community), 
                                       ref = "Rural")
study1_responses$pid3 <- relevel(as.factor(study1_responses$pid3), 
                                      ref = "R")

################################################################################
################################################################################

# MAIN PAPER

# FIGURE 1

# AMCEs among all respondents (choice outcome)
choice_model <- lm(choice ~ temp + attractions + traveltime + preselec + recentnews + community,
                   data = study1_responses)
# calculating variance-covariance matrix for cluster robust SEs (clustered on respondent)
choice_model_vcov <- cluster.vcov(choice_model, cluster = study1_responses$ResponseId)
# model summary with CRSEs
coeftest(choice_model, choice_model_vcov)
# saving SEs, p-values, and the variance-covariance matrix
choice_model_vcov_ses <- coeftest(choice_model, choice_model_vcov)[,2]
choice_model_vcov_pvals <- coeftest(choice_model, choice_model_vcov)[,4]
choice_model_crse <- withVCov(choice_model, choice_model_vcov)

# ACIEs among Democrats and Republicans (choice outcome)
# model conditions every non-baseline attribute level on PID (1 if Democrat, 0
# if Republican); ACIEs are then calculated from estimated coefficients using
# glht from the multcomp package (for Republicans, coefficients for 
# attribute-levels themselves are used; for Democrats, the combination of the 
# coefficients from the attribute-levels themselves AND the corresponding terms 
# that interact PID and attribute-levels are used)
choice_model_pid <- lm(choice ~ temp + attractions + traveltime + 
                         preselec + recentnews + community + pid3 +
                         temp:pid3 + attractions:pid3 + traveltime:pid3 + 
                         preselec:pid3 + recentnews:pid3 + community:pid3,
                       data = study1_responses[which(study1_responses$pid3=="D" |
                                                        study1_responses$pid3=="R")])
# calculating variance-covariance matrix for cluster robust SEs (clustered on respondent)
choice_model_pid_vcov <- cluster.vcov(choice_model_pid, 
                                      cluster = study1_responses$ResponseId[which(study1_responses$pid3=="D" |
                                                                                   study1_responses$pid3=="R")])
# model summary with CRSEs
coeftest(choice_model_pid, choice_model_pid_vcov)
# saving SEs, p-values, and the cariance-covariance matrix
choice_model_pid_vcov_ses <- coeftest(choice_model_pid, choice_model_pid_vcov)[,2]
choice_model_pid_vcov_pvals <- coeftest(choice_model_pid, choice_model_pid_vcov)[,4]
choice_model_pid_crse <- withVCov(choice_model_pid, choice_model_pid_vcov)

# obtaining ACIEs and corresponding 95% confidence intervals for each
# non-baseline attribute-level among Democrats and Republicans as described above
# (object names indicate which ACIEs are stored therein)

# ACIEs for Democrats
temp67_choice_D <- confint(glht(choice_model_pid_crse, 
                                linfct = "temp67 + temp67:pid3D = 0"))
temp72_choice_D <- confint(glht(choice_model_pid_crse, 
                                linfct = "temp72 + temp72:pid3D = 0"))
temp78_choice_D <- confint(glht(choice_model_pid_crse, 
                                linfct = "temp78 + temp78:pid3D = 0"))
communitySuburban_choice_D <- confint(glht(choice_model_pid_crse, 
                                           linfct = "communitySuburban + communitySuburban:pid3D = 0"))
communityUrban_choice_D <- confint(glht(choice_model_pid_crse, 
                                        linfct = "communityUrban + communityUrban:pid3D = 0"))
attractionsBeaches_choice_D <- confint(glht(choice_model_pid_crse, 
                                            linfct = "attractionsBeaches + attractionsBeaches:pid3D = 0"))
attractionsMuseums_choice_D <- confint(glht(choice_model_pid_crse, 
                                            linfct = "attractionsMuseums + attractionsMuseums:pid3D = 0"))
attractionsParks_choice_D <- confint(glht(choice_model_pid_crse, 
                                          linfct = "`attractionsNational parks` + `attractionsNational parks:pid3D` = 0"))
attractionsSports_choice_D <- confint(glht(choice_model_pid_crse, 
                                           linfct = "`attractionsSporting events` + `attractionsSporting events:pid3D` = 0"))
attractionsTheaters_choice_D <- confint(glht(choice_model_pid_crse, 
                                             linfct = "attractionsTheaters + attractionsTheaters:pid3D = 0"))
traveltime2to4hours_choice_D <- confint(glht(choice_model_pid_crse, 
                                             linfct = "`traveltime2-4 hours` + `traveltime2-4 hours:pid3D` = 0"))
traveltime4to6hours_choice_D <- confint(glht(choice_model_pid_crse, 
                                             linfct = "`traveltime4-6 hours` + `traveltime4-6 hours:pid3D` = 0"))
traveltime6Plushours_choice_D <- confint(glht(choice_model_pid_crse, 
                                              linfct = "`traveltimeMore than 6 hours` + `traveltimeMore than 6 hours:pid3D` = 0"))
preselecSmallTrumpMargin_choice_D <- confint(glht(choice_model_pid_crse, 
                                                  linfct = "`preselecDonald Trump won by a small margin` + `preselecDonald Trump won by a small margin:pid3D` = 0"))
preselecSmallBidenMargin_choice_D <- confint(glht(choice_model_pid_crse, 
                                                  linfct = "`preselecJoe Biden won by a small margin` + `preselecJoe Biden won by a small margin:pid3D` = 0"))
preselecLargeBidenMargin_choice_D <- confint(glht(choice_model_pid_crse, 
                                                  linfct = "`preselecJoe Biden won by a large margin` + `preselecJoe Biden won by a large margin:pid3D` = 0"))
recentnewsExpandProtest_choice_D <- confint(glht(choice_model_pid_crse, 
                                                 linfct = "`recentnewsState legislature enacted a law to expand the right to protest at the state capitol building` + `recentnewsState legislature enacted a law to expand the right to protest at the state capitol building:pid3D` = 0"))
recentnewsExpandEarlyVoting_choice_D <- confint(glht(choice_model_pid_crse, 
                                                     linfct = "`recentnewsState legislature enacted a law to expand voters ability to vote early in elections` + `recentnewsState legislature enacted a law to expand voters ability to vote early in elections:pid3D` = 0"))
recentnewsLimitProtest_choice_D <- confint(glht(choice_model_pid_crse, 
                                                linfct = "`recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` + `recentnewsState legislature enacted a law to limit the right to protest at the state capitol building:pid3D` = 0"))
recentnewsLimitEarlyVoting_choice_D <- confint(glht(choice_model_pid_crse, 
                                                    linfct = "`recentnewsState legislature enacted a law to limit voters ability to vote early in elections` + `recentnewsState legislature enacted a law to limit voters ability to vote early in elections:pid3D` = 0"))

# ACIEs for Republicans
temp67_choice_R <- confint(glht(choice_model_pid_crse, 
                                linfct = "temp67 = 0"))
temp72_choice_R <- confint(glht(choice_model_pid_crse, 
                                linfct = "temp72 = 0"))
temp78_choice_R <- confint(glht(choice_model_pid_crse, 
                                linfct = "temp78 = 0"))
communitySuburban_choice_R <- confint(glht(choice_model_pid_crse, 
                                           linfct = "communitySuburban = 0"))
communityUrban_choice_R <- confint(glht(choice_model_pid_crse, 
                                        linfct = "communityUrban = 0"))
attractionsBeaches_choice_R <- confint(glht(choice_model_pid_crse, 
                                            linfct = "attractionsBeaches = 0"))
attractionsMuseums_choice_R <- confint(glht(choice_model_pid_crse, 
                                            linfct = "attractionsMuseums = 0"))
attractionsParks_choice_R <- confint(glht(choice_model_pid_crse, 
                                          linfct = "`attractionsNational parks` = 0"))
attractionsSports_choice_R <- confint(glht(choice_model_pid_crse, 
                                           linfct = "`attractionsSporting events` = 0"))
attractionsTheaters_choice_R <- confint(glht(choice_model_pid_crse, 
                                             linfct = "attractionsTheaters = 0"))
traveltime2to4hours_choice_R <- confint(glht(choice_model_pid_crse, 
                                             linfct = "`traveltime2-4 hours` = 0"))
traveltime4to6hours_choice_R <- confint(glht(choice_model_pid_crse, 
                                             linfct = "`traveltime4-6 hours` = 0"))
traveltime6Plushours_choice_R <- confint(glht(choice_model_pid_crse, 
                                              linfct = "`traveltimeMore than 6 hours` = 0"))
preselecSmallTrumpMargin_choice_R <- confint(glht(choice_model_pid_crse, 
                                                  linfct = "`preselecDonald Trump won by a small margin` = 0"))
preselecSmallBidenMargin_choice_R <- confint(glht(choice_model_pid_crse, 
                                                  linfct = "`preselecJoe Biden won by a small margin` = 0"))
preselecLargeBidenMargin_choice_R <- confint(glht(choice_model_pid_crse, 
                                                  linfct = "`preselecJoe Biden won by a large margin` = 0"))
recentnewsExpandProtest_choice_R <- confint(glht(choice_model_pid_crse, 
                                                 linfct = "`recentnewsState legislature enacted a law to expand the right to protest at the state capitol building` = 0"))
recentnewsExpandEarlyVoting_choice_R <- confint(glht(choice_model_pid_crse, 
                                                     linfct = "`recentnewsState legislature enacted a law to expand voters ability to vote early in elections` = 0"))
recentnewsLimitProtest_choice_R <- confint(glht(choice_model_pid_crse, 
                                                linfct = "`recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` = 0"))
recentnewsLimitEarlyVoting_choice_R <- confint(glht(choice_model_pid_crse, 
                                                    linfct = "`recentnewsState legislature enacted a law to limit voters ability to vote early in elections`= 0"))

# Creating Figure 1 using the choice-based AMCEs/ACIEs obtained above.  Please note
# that the AMCEs for all respondents can be extracted directly from the 
# choice_model_crse object because they are not conditioned on any respondnet-level
# attributes, while the ACIEs for Democrats and Republicans are extracted from
# the objects created using glht because they (specifically, those for
# Democratic respondents) rely on combinations of coefficients.

png(file = "all-choice.png", family = "sans", height = 15.5, width=22,
    units = "in", res = 1200)
par(mar=c(5.1,17,2.5,0.5))
# plotting the AMCE/ACIE point estimates (first for all respondents, then among
# Democrats, and then among Republicans)
plot(x=rev(c(0,
             choice_model_crse$coefficients["recentnewsState legislature enacted a law to expand the right to protest at the state capitol building"],
             choice_model_crse$coefficients["recentnewsState legislature enacted a law to expand voters ability to vote early in elections"],
             choice_model_crse$coefficients["recentnewsState legislature enacted a law to limit the right to protest at the state capitol building"],
             choice_model_crse$coefficients["recentnewsState legislature enacted a law to limit voters ability to vote early in elections"],
             0,
             choice_model_crse$coefficients["temp67"],
             choice_model_crse$coefficients["temp72"],
             choice_model_crse$coefficients["temp78"],
             0,
             choice_model_crse$coefficients["communitySuburban"],
             choice_model_crse$coefficients["communityUrban"],
             0,
             choice_model_crse$coefficients["attractionsBeaches"],
             choice_model_crse$coefficients["attractionsMuseums"],
             choice_model_crse$coefficients["attractionsNational parks"],
             choice_model_crse$coefficients["attractionsSporting events"],
             choice_model_crse$coefficients["attractionsTheaters"],
             0,
             choice_model_crse$coefficients["traveltime2-4 hours"],
             choice_model_crse$coefficients["traveltime4-6 hours"],
             choice_model_crse$coefficients["traveltimeMore than 6 hours"],
             0,
             choice_model_crse$coefficients["preselecDonald Trump won by a small margin"],
             choice_model_crse$coefficients["preselecJoe Biden won by a small margin"],
             choice_model_crse$coefficients["preselecJoe Biden won by a large margin"],
             0.6,
             recentnewsExpandProtest_choice_D$confint[,"Estimate"]+0.6,
             recentnewsExpandEarlyVoting_choice_D$confint[,"Estimate"]+0.6,
             recentnewsLimitProtest_choice_D$confint[,"Estimate"]+0.6,
             recentnewsLimitEarlyVoting_choice_D$confint[,"Estimate"]+0.6,
             0.6,
             temp67_choice_D$confint[,"Estimate"]+0.6,
             temp72_choice_D$confint[,"Estimate"]+0.6,
             temp78_choice_D$confint[,"Estimate"]+0.6,
             0.6,
             communitySuburban_choice_D$confint[,"Estimate"]+0.6,
             communityUrban_choice_D$confint[,"Estimate"]+0.6,
             0.6,
             attractionsBeaches_choice_D$confint[,"Estimate"]+0.6,
             attractionsMuseums_choice_D$confint[,"Estimate"]+0.6,
             attractionsParks_choice_D$confint[,"Estimate"]+0.6,
             attractionsSports_choice_D$confint[,"Estimate"]+0.6,
             attractionsTheaters_choice_D$confint[,"Estimate"]+0.6,
             0.6,
             traveltime2to4hours_choice_D$confint[,"Estimate"]+0.6,
             traveltime4to6hours_choice_D$confint[,"Estimate"]+0.6,
             traveltime6Plushours_choice_D$confint[,"Estimate"]+0.6,
             0.6,
             preselecSmallTrumpMargin_choice_D$confint[,"Estimate"]+0.6,
             preselecSmallBidenMargin_choice_D$confint[,"Estimate"]+0.6,
             preselecLargeBidenMargin_choice_D$confint[,"Estimate"]+0.6,
             1.2,
             recentnewsExpandProtest_choice_R$confint[,"Estimate"]+1.2,
             recentnewsExpandEarlyVoting_choice_R$confint[,"Estimate"]+1.2,
             recentnewsLimitProtest_choice_R$confint[,"Estimate"]+1.2,
             recentnewsLimitEarlyVoting_choice_R$confint[,"Estimate"]+1.2,
             1.2,
             temp67_choice_R$confint[,"Estimate"]+1.2,
             temp72_choice_R$confint[,"Estimate"]+1.2,
             temp78_choice_R$confint[,"Estimate"]+1.2,
             1.2,
             communitySuburban_choice_R$confint[,"Estimate"]+1.2,
             communityUrban_choice_R$confint[,"Estimate"]+1.2,
             1.2,
             attractionsBeaches_choice_R$confint[,"Estimate"]+1.2,
             attractionsMuseums_choice_R$confint[,"Estimate"]+1.2,
             attractionsParks_choice_R$confint[,"Estimate"]+1.2,
             attractionsSports_choice_R$confint[,"Estimate"]+1.2,
             attractionsTheaters_choice_R$confint[,"Estimate"]+1.2,
             1.2,
             traveltime2to4hours_choice_R$confint[,"Estimate"]+1.2,
             traveltime4to6hours_choice_R$confint[,"Estimate"]+1.2,
             traveltime6Plushours_choice_R$confint[,"Estimate"]+1.2,
             1.2,
             preselecSmallTrumpMargin_choice_R$confint[,"Estimate"]+1.2,
             preselecSmallBidenMargin_choice_R$confint[,"Estimate"]+1.2,
             preselecLargeBidenMargin_choice_R$confint[,"Estimate"]+1.2
             
)),
y=rep(c(1:4, 7:10, 13:18, 21:23, 26:29, 32:36),3),
xlim=c(-.20,1.4),
xaxt="n",
ylim=c(0.5, 36.5),
pch=19,
tck=-.02,
cex.axis=0.9,
cex=1.25,
ylab="",
yaxt="n",
xlab="",
axes = FALSE,
panel.first = c(abline(v=0,lwd=2, col="gray90",lty=2),
                abline(v=0.6,lwd=2, col="gray90",lty=2),
                abline(v=1.2,lwd=2, col="gray90",lty=2)))
# plotting the 95% confidence intervals for the corresponding AMCEs/ACIEs
segments(x0=rev(c(0,
                  confint(choice_model_crse)["recentnewsState legislature enacted a law to expand the right to protest at the state capitol building",1],
                  confint(choice_model_crse)["recentnewsState legislature enacted a law to expand voters ability to vote early in elections",1],
                  confint(choice_model_crse)["recentnewsState legislature enacted a law to limit the right to protest at the state capitol building",1],
                  confint(choice_model_crse)["recentnewsState legislature enacted a law to limit voters ability to vote early in elections",1],
                  0,
                  confint(choice_model_crse)["temp67",1],
                  confint(choice_model_crse)["temp72",1],
                  confint(choice_model_crse)["temp78",1],
                  0,
                  confint(choice_model_crse)["communitySuburban",1],
                  confint(choice_model_crse)["communityUrban",1],
                  0,
                  confint(choice_model_crse)["attractionsBeaches",1],
                  confint(choice_model_crse)["attractionsMuseums",1],
                  confint(choice_model_crse)["attractionsNational parks",1],
                  confint(choice_model_crse)["attractionsSporting events",1],
                  confint(choice_model_crse)["attractionsTheaters",1],
                  0,
                  confint(choice_model_crse)["traveltime2-4 hours",1],
                  confint(choice_model_crse)["traveltime4-6 hours",1],
                  confint(choice_model_crse)["traveltimeMore than 6 hours",1],
                  0,
                  confint(choice_model_crse)["preselecDonald Trump won by a small margin",1],
                  confint(choice_model_crse)["preselecJoe Biden won by a small margin",1],
                  confint(choice_model_crse)["preselecJoe Biden won by a large margin",1],
                  0.6,
                  recentnewsExpandProtest_choice_D$confint[,"lwr"]+0.6,
                  recentnewsExpandEarlyVoting_choice_D$confint[,"lwr"]+0.6,
                  recentnewsLimitProtest_choice_D$confint[,"lwr"]+0.6,
                  recentnewsLimitEarlyVoting_choice_D$confint[,"lwr"]+0.6,
                  0.6,
                  temp67_choice_D$confint[,"lwr"]+0.6,
                  temp72_choice_D$confint[,"lwr"]+0.6,
                  temp78_choice_D$confint[,"lwr"]+0.6,
                  0.6,
                  communitySuburban_choice_D$confint[,"lwr"]+0.6,
                  communityUrban_choice_D$confint[,"lwr"]+0.6,
                  0.6,
                  attractionsBeaches_choice_D$confint[,"lwr"]+0.6,
                  attractionsMuseums_choice_D$confint[,"lwr"]+0.6,
                  attractionsParks_choice_D$confint[,"lwr"]+0.6,
                  attractionsSports_choice_D$confint[,"lwr"]+0.6,
                  attractionsTheaters_choice_D$confint[,"lwr"]+0.6,
                  0.6,
                  traveltime2to4hours_choice_D$confint[,"lwr"]+0.6,
                  traveltime4to6hours_choice_D$confint[,"lwr"]+0.6,
                  traveltime6Plushours_choice_D$confint[,"lwr"]+0.6,
                  0.6,
                  preselecSmallTrumpMargin_choice_D$confint[,"lwr"]+0.6,
                  preselecSmallBidenMargin_choice_D$confint[,"lwr"]+0.6,
                  preselecLargeBidenMargin_choice_D$confint[,"lwr"]+0.6,
                  1.2,
                  recentnewsExpandProtest_choice_R$confint[,"lwr"]+1.2,
                  recentnewsExpandEarlyVoting_choice_R$confint[,"lwr"]+1.2,
                  recentnewsLimitProtest_choice_R$confint[,"lwr"]+1.2,
                  recentnewsLimitEarlyVoting_choice_R$confint[,"lwr"]+1.2,
                  1.2,
                  temp67_choice_R$confint[,"lwr"]+1.2,
                  temp72_choice_R$confint[,"lwr"]+1.2,
                  temp78_choice_R$confint[,"lwr"]+1.2,
                  1.2,
                  communitySuburban_choice_R$confint[,"lwr"]+1.2,
                  communityUrban_choice_R$confint[,"lwr"]+1.2,
                  1.2,
                  attractionsBeaches_choice_R$confint[,"lwr"]+1.2,
                  attractionsMuseums_choice_R$confint[,"lwr"]+1.2,
                  attractionsParks_choice_R$confint[,"lwr"]+1.2,
                  attractionsSports_choice_R$confint[,"lwr"]+1.2,
                  attractionsTheaters_choice_R$confint[,"lwr"]+1.2,
                  1.2,
                  traveltime2to4hours_choice_R$confint[,"lwr"]+1.2,
                  traveltime4to6hours_choice_R$confint[,"lwr"]+1.2,
                  traveltime6Plushours_choice_R$confint[,"lwr"]+1.2,
                  1.2,
                  preselecSmallTrumpMargin_choice_R$confint[,"lwr"]+1.2,
                  preselecSmallBidenMargin_choice_R$confint[,"lwr"]+1.2,
                  preselecLargeBidenMargin_choice_R$confint[,"lwr"]+1.2
)),
x1=rev(c(0,
         confint(choice_model_crse)["recentnewsState legislature enacted a law to expand the right to protest at the state capitol building",2],
         confint(choice_model_crse)["recentnewsState legislature enacted a law to expand voters ability to vote early in elections",2],
         confint(choice_model_crse)["recentnewsState legislature enacted a law to limit the right to protest at the state capitol building",2],
         confint(choice_model_crse)["recentnewsState legislature enacted a law to limit voters ability to vote early in elections",2],
         0,
         confint(choice_model_crse)["temp67",2],
         confint(choice_model_crse)["temp72",2],
         confint(choice_model_crse)["temp78",2],
         0,
         confint(choice_model_crse)["communitySuburban",2],
         confint(choice_model_crse)["communityUrban",2],
         0,
         confint(choice_model_crse)["attractionsBeaches",2],
         confint(choice_model_crse)["attractionsMuseums",2],
         confint(choice_model_crse)["attractionsNational parks",2],
         confint(choice_model_crse)["attractionsSporting events",2],
         confint(choice_model_crse)["attractionsTheaters",2],
         0,
         confint(choice_model_crse)["traveltime2-4 hours",2],
         confint(choice_model_crse)["traveltime4-6 hours",2],
         confint(choice_model_crse)["traveltimeMore than 6 hours",2],
         0,
         confint(choice_model_crse)["preselecDonald Trump won by a small margin",2],
         confint(choice_model_crse)["preselecJoe Biden won by a small margin",2],
         confint(choice_model_crse)["preselecJoe Biden won by a large margin",2],
         0.6,
         recentnewsExpandProtest_choice_D$confint[,"upr"]+0.6,
         recentnewsExpandEarlyVoting_choice_D$confint[,"upr"]+0.6,
         recentnewsLimitProtest_choice_D$confint[,"upr"]+0.6,
         recentnewsLimitEarlyVoting_choice_D$confint[,"upr"]+0.6,
         0.6,
         temp67_choice_D$confint[,"upr"]+0.6,
         temp72_choice_D$confint[,"upr"]+0.6,
         temp78_choice_D$confint[,"upr"]+0.6,
         0.6,
         communitySuburban_choice_D$confint[,"upr"]+0.6,
         communityUrban_choice_D$confint[,"upr"]+0.6,
         0.6,
         attractionsBeaches_choice_D$confint[,"upr"]+0.6,
         attractionsMuseums_choice_D$confint[,"upr"]+0.6,
         attractionsParks_choice_D$confint[,"upr"]+0.6,
         attractionsSports_choice_D$confint[,"upr"]+0.6,
         attractionsTheaters_choice_D$confint[,"upr"]+0.6,
         0.6,
         traveltime2to4hours_choice_D$confint[,"upr"]+0.6,
         traveltime4to6hours_choice_D$confint[,"upr"]+0.6,
         traveltime6Plushours_choice_D$confint[,"upr"]+0.6,
         0.6,
         preselecSmallTrumpMargin_choice_D$confint[,"upr"]+0.6,
         preselecSmallBidenMargin_choice_D$confint[,"upr"]+0.6,
         preselecLargeBidenMargin_choice_D$confint[,"upr"]+0.6,
         1.2,
         recentnewsExpandProtest_choice_R$confint[,"upr"]+1.2,
         recentnewsExpandEarlyVoting_choice_R$confint[,"upr"]+1.2,
         recentnewsLimitProtest_choice_R$confint[,"upr"]+1.2,
         recentnewsLimitEarlyVoting_choice_R$confint[,"upr"]+1.2,
         1.2,
         temp67_choice_R$confint[,"upr"]+1.2,
         temp72_choice_R$confint[,"upr"]+1.2,
         temp78_choice_R$confint[,"upr"]+1.2,
         1.2,
         communitySuburban_choice_R$confint[,"upr"]+1.2,
         communityUrban_choice_R$confint[,"upr"]+1.2,
         1.2,
         attractionsBeaches_choice_R$confint[,"upr"]+1.2,
         attractionsMuseums_choice_R$confint[,"upr"]+1.2,
         attractionsParks_choice_R$confint[,"upr"]+1.2,
         attractionsSports_choice_R$confint[,"upr"]+1.2,
         attractionsTheaters_choice_R$confint[,"upr"]+1.2,
         1.2,
         traveltime2to4hours_choice_R$confint[,"upr"]+1.2,
         traveltime4to6hours_choice_R$confint[,"upr"]+1.2,
         traveltime6Plushours_choice_R$confint[,"upr"]+1.2,
         1.2,
         preselecSmallTrumpMargin_choice_R$confint[,"upr"]+1.2,
         preselecSmallBidenMargin_choice_R$confint[,"upr"]+1.2,
         preselecLargeBidenMargin_choice_R$confint[,"upr"]+1.2
)),
y0=c(1:4, 7:10, 13:18, 21:23, 26:29, 32:36))
# creating x-axis labels for magnitudes of ACMEs/ACIEs
axis(1,at=c(-.2, -.1, 0, .1, .2), 
     labels = c("-20%", "-10%", "0%", "10%", "20%"), cex.axis = 1.5)
axis(1,at=c(.4, .5, .6, .7, .8), 
     labels = c("-20%", "-10%", "0%", "10%", "20%"), cex.axis = 1.5)
axis(1,at=c(1.0, 1.1, 1.2, 1.3, 1.4), 
     labels = c("-20%", "-10%", "0%", "10%", "20%"), cex.axis = 1.5)
mtext("Effect on selection", side = 1, at=0.6, line = 3, cex = 1.75)
# labeling each pane to indicate which respondents are included
mtext("All Respondents", side = 3, at=0, line=0.5, cex = 2.5)
mtext("Only Democrats", side = 3, at=0.6, line=0.5, cex = 2.5)
mtext("Only Republicans", side = 3, at=1.2, line=0.5, cex = 2.5)
# providing y-axis labels to indicate which attributes and levels are conveys
# by each point estimate
par(mgp=c(0,11,0))
axis(2,at=c(1:4, 7:10, 13:18, 21:23, 26:29, 32:36),
     las=2,
     labels=rev(c("Created economic growth committee",
                  "Expanded right to protest",
                  "Expanded early voting",
                  "Limited right to protest",
                  "Limited early voting",
                  "64�F","67�F","72�F","78�F",
                  "Rural", "Suburban", "Urban",
                  "Amusement parks", "Beaches", "Museums", "National parks", 
                  "Sporting events", "Theaters",
                  "Less than 2 hours", "2-4 hours", "4-6 hours", "More than 6 hours",
                  "Trump won by large margin", "Trump won by small margin", 
                  "Biden won by small margin", "Biden won by large margin"
     )),
     tck=0,
     lwd = 0,
     line = 3,
     cex.axis=1.5, hadj=0)
par(mgp=c(0,13,0))
axis(2,at=c(5, 11, 19, 24, 30, 37),
     las=2,
     labels=rev(c(expression(~bold(~underline("Recent State News"))),
                  expression(~bold(~underline("Avg. Temperature"))), 
                  expression(~bold(~underline("Community Type"))), 
                  expression(~bold(~underline("Main Attractions"))),
                  expression(~bold(~underline("Travel Time"))),
                  expression(~bold(~underline("2020 Pres. Election Result")))
     )),
     tck=0,
     lwd = 0,
     line = 3,
     cex.axis=1.5, hadj=0)
# printing numerical values for each point estimate
text(rev(c(choice_model_crse$coefficients["recentnewsState legislature enacted a law to expand the right to protest at the state capitol building"],
           choice_model_crse$coefficients["recentnewsState legislature enacted a law to expand voters ability to vote early in elections"],
           choice_model_crse$coefficients["recentnewsState legislature enacted a law to limit the right to protest at the state capitol building"],
           choice_model_crse$coefficients["recentnewsState legislature enacted a law to limit voters ability to vote early in elections"],
           choice_model_crse$coefficients["temp67"],
           choice_model_crse$coefficients["temp72"],
           choice_model_crse$coefficients["temp78"],
           choice_model_crse$coefficients["communitySuburban"],
           choice_model_crse$coefficients["communityUrban"],
           choice_model_crse$coefficients["attractionsBeaches"],
           choice_model_crse$coefficients["attractionsMuseums"],
           choice_model_crse$coefficients["attractionsNational parks"],
           choice_model_crse$coefficients["attractionsSporting events"],
           choice_model_crse$coefficients["attractionsTheaters"],
           choice_model_crse$coefficients["traveltime2-4 hours"],
           choice_model_crse$coefficients["traveltime4-6 hours"],
           choice_model_crse$coefficients["traveltimeMore than 6 hours"],
           choice_model_crse$coefficients["preselecDonald Trump won by a small margin"],
           choice_model_crse$coefficients["preselecJoe Biden won by a small margin"],
           choice_model_crse$coefficients["preselecJoe Biden won by a large margin"],
           recentnewsExpandProtest_choice_D$confint[,"Estimate"]+0.6,
           recentnewsExpandEarlyVoting_choice_D$confint[,"Estimate"]+0.6,
           recentnewsLimitProtest_choice_D$confint[,"Estimate"]+0.6,
           recentnewsLimitEarlyVoting_choice_D$confint[,"Estimate"]+0.6,
           temp67_choice_D$confint[,"Estimate"]+0.6,
           temp72_choice_D$confint[,"Estimate"]+0.6,
           temp78_choice_D$confint[,"Estimate"]+0.6,
           communitySuburban_choice_D$confint[,"Estimate"]+0.6,
           communityUrban_choice_D$confint[,"Estimate"]+0.6,
           attractionsBeaches_choice_D$confint[,"Estimate"]+0.6,
           attractionsMuseums_choice_D$confint[,"Estimate"]+0.6,
           attractionsParks_choice_D$confint[,"Estimate"]+0.6,
           attractionsSports_choice_D$confint[,"Estimate"]+0.6,
           attractionsTheaters_choice_D$confint[,"Estimate"]+0.6,
           traveltime2to4hours_choice_D$confint[,"Estimate"]+0.6,
           traveltime4to6hours_choice_D$confint[,"Estimate"]+0.6,
           traveltime6Plushours_choice_D$confint[,"Estimate"]+0.6,
           preselecSmallTrumpMargin_choice_D$confint[,"Estimate"]+0.6,
           preselecSmallBidenMargin_choice_D$confint[,"Estimate"]+0.6,
           preselecLargeBidenMargin_choice_D$confint[,"Estimate"]+0.6,
           recentnewsExpandProtest_choice_R$confint[,"Estimate"]+1.2,
           recentnewsExpandEarlyVoting_choice_R$confint[,"Estimate"]+1.2,
           recentnewsLimitProtest_choice_R$confint[,"Estimate"]+1.2,
           recentnewsLimitEarlyVoting_choice_R$confint[,"Estimate"]+1.2,
           temp67_choice_R$confint[,"Estimate"]+1.2,
           temp72_choice_R$confint[,"Estimate"]+1.2,
           temp78_choice_R$confint[,"Estimate"]+1.2,
           communitySuburban_choice_R$confint[,"Estimate"]+1.2,
           communityUrban_choice_R$confint[,"Estimate"]+1.2,
           attractionsBeaches_choice_R$confint[,"Estimate"]+1.2,
           attractionsMuseums_choice_R$confint[,"Estimate"]+1.2,
           attractionsParks_choice_R$confint[,"Estimate"]+1.2,
           attractionsSports_choice_R$confint[,"Estimate"]+1.2,
           attractionsTheaters_choice_R$confint[,"Estimate"]+1.2,
           traveltime2to4hours_choice_R$confint[,"Estimate"]+1.2,
           traveltime4to6hours_choice_R$confint[,"Estimate"]+1.2,
           traveltime6Plushours_choice_R$confint[,"Estimate"]+1.2,
           preselecSmallTrumpMargin_choice_R$confint[,"Estimate"]+1.2,
           preselecSmallBidenMargin_choice_R$confint[,"Estimate"]+1.2,
           preselecLargeBidenMargin_choice_R$confint[,"Estimate"]+1.2
)),
c(1:3, 7:9, 13:17, 21:22, 26:28, 32:35) + 0.4,
paste0(sprintf("%.0f",rev(c(choice_model_crse$coefficients["recentnewsState legislature enacted a law to expand the right to protest at the state capitol building"],
                            choice_model_crse$coefficients["recentnewsState legislature enacted a law to expand voters ability to vote early in elections"],
                            choice_model_crse$coefficients["recentnewsState legislature enacted a law to limit the right to protest at the state capitol building"],
                            choice_model_crse$coefficients["recentnewsState legislature enacted a law to limit voters ability to vote early in elections"],
                            choice_model_crse$coefficients["temp67"],
                            choice_model_crse$coefficients["temp72"],
                            choice_model_crse$coefficients["temp78"],
                            choice_model_crse$coefficients["communitySuburban"],
                            choice_model_crse$coefficients["communityUrban"],
                            choice_model_crse$coefficients["attractionsBeaches"],
                            choice_model_crse$coefficients["attractionsMuseums"],
                            choice_model_crse$coefficients["attractionsNational parks"],
                            choice_model_crse$coefficients["attractionsSporting events"],
                            choice_model_crse$coefficients["attractionsTheaters"],
                            choice_model_crse$coefficients["traveltime2-4 hours"],
                            choice_model_crse$coefficients["traveltime4-6 hours"],
                            choice_model_crse$coefficients["traveltimeMore than 6 hours"],
                            choice_model_crse$coefficients["preselecDonald Trump won by a small margin"],
                            choice_model_crse$coefficients["preselecJoe Biden won by a small margin"],
                            choice_model_crse$coefficients["preselecJoe Biden won by a large margin"],
                            recentnewsExpandProtest_choice_D$confint[,"Estimate"],
                            recentnewsExpandEarlyVoting_choice_D$confint[,"Estimate"],
                            recentnewsLimitProtest_choice_D$confint[,"Estimate"],
                            recentnewsLimitEarlyVoting_choice_D$confint[,"Estimate"],
                            temp67_choice_D$confint[,"Estimate"],
                            temp72_choice_D$confint[,"Estimate"],
                            temp78_choice_D$confint[,"Estimate"],
                            communitySuburban_choice_D$confint[,"Estimate"],
                            communityUrban_choice_D$confint[,"Estimate"],
                            attractionsBeaches_choice_D$confint[,"Estimate"],
                            attractionsMuseums_choice_D$confint[,"Estimate"],
                            attractionsParks_choice_D$confint[,"Estimate"],
                            attractionsSports_choice_D$confint[,"Estimate"],
                            attractionsTheaters_choice_D$confint[,"Estimate"],
                            traveltime2to4hours_choice_D$confint[,"Estimate"],
                            traveltime4to6hours_choice_D$confint[,"Estimate"],
                            traveltime6Plushours_choice_D$confint[,"Estimate"],
                            preselecSmallTrumpMargin_choice_D$confint[,"Estimate"],
                            preselecSmallBidenMargin_choice_D$confint[,"Estimate"],
                            preselecLargeBidenMargin_choice_D$confint[,"Estimate"],
                            recentnewsExpandProtest_choice_R$confint[,"Estimate"],
                            recentnewsExpandEarlyVoting_choice_R$confint[,"Estimate"],
                            recentnewsLimitProtest_choice_R$confint[,"Estimate"],
                            recentnewsLimitEarlyVoting_choice_R$confint[,"Estimate"],
                            temp67_choice_R$confint[,"Estimate"],
                            temp72_choice_R$confint[,"Estimate"],
                            temp78_choice_R$confint[,"Estimate"],
                            communitySuburban_choice_R$confint[,"Estimate"],
                            communityUrban_choice_R$confint[,"Estimate"],
                            attractionsBeaches_choice_R$confint[,"Estimate"],
                            attractionsMuseums_choice_R$confint[,"Estimate"],
                            attractionsParks_choice_R$confint[,"Estimate"],
                            attractionsSports_choice_R$confint[,"Estimate"],
                            attractionsTheaters_choice_R$confint[,"Estimate"],
                            traveltime2to4hours_choice_R$confint[,"Estimate"],
                            traveltime4to6hours_choice_R$confint[,"Estimate"],
                            traveltime6Plushours_choice_R$confint[,"Estimate"],
                            preselecSmallTrumpMargin_choice_R$confint[,"Estimate"],
                            preselecSmallBidenMargin_choice_R$confint[,"Estimate"],
                            preselecLargeBidenMargin_choice_R$confint[,"Estimate"]
))*100, 0),"%"), cex=1.5)
dev.off()

################################################################################

# The text in the main paper makes mention of the comparisons of the non-baseline
# values of the AMCEs/ACIEs for recent state news--specifically, that news
# consistent with backsliding has larger negative effects than does news consistent
# with expanding democracy among all respondents and among Democrats, but not
# among Republicans.  The code below uses glht to formally conduct those
# hypothesis tests.

# among all respondents, limit protest vs. expand protest
summary(glht(choice_model_crse, 
             linfct = "`recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` - `recentnewsState legislature enacted a law to expand the right to protest at the state capitol building` = 0"))

# among all respondents, expand protest vs. limit voting
summary(glht(choice_model_crse, 
             linfct = "`recentnewsState legislature enacted a law to expand the right to protest at the state capitol building` - `recentnewsState legislature enacted a law to limit voters ability to vote early in elections` = 0"))

# among all respondents, expand voting vs. limit voting
summary(glht(choice_model_crse, 
             linfct = "`recentnewsState legislature enacted a law to expand voters ability to vote early in elections` - `recentnewsState legislature enacted a law to limit voters ability to vote early in elections` = 0"))

# among all respondents, expand voting vs. limit protest
summary(glht(choice_model_crse, 
             linfct = "`recentnewsState legislature enacted a law to expand voters ability to vote early in elections` - `recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` = 0"))

# among Democratic respondents, limit protest vs. expand protest
summary(glht(choice_model_pid_crse, 
             linfct = "`recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` + `recentnewsState legislature enacted a law to limit the right to protest at the state capitol building:pid3D` - `recentnewsState legislature enacted a law to expand the right to protest at the state capitol building` - `recentnewsState legislature enacted a law to expand the right to protest at the state capitol building:pid3D` = 0"))

# among Democratic respondents, expand protest vs. limit voting
summary(glht(choice_model_pid_crse, 
             linfct = "`recentnewsState legislature enacted a law to expand the right to protest at the state capitol building` + `recentnewsState legislature enacted a law to expand the right to protest at the state capitol building:pid3D` - `recentnewsState legislature enacted a law to limit voters ability to vote early in elections` - `recentnewsState legislature enacted a law to limit voters ability to vote early in elections:pid3D` = 0"))

# among Democratic respondents, expand voting vs. limit voting
summary(glht(choice_model_pid_crse, 
             linfct = "`recentnewsState legislature enacted a law to expand voters ability to vote early in elections` + `recentnewsState legislature enacted a law to expand voters ability to vote early in elections:pid3D` - `recentnewsState legislature enacted a law to limit voters ability to vote early in elections` - `recentnewsState legislature enacted a law to limit voters ability to vote early in elections:pid3D` = 0"))

# among Democratic respondents, expand voting vs. limit protest
summary(glht(choice_model_pid_crse, 
             linfct = "`recentnewsState legislature enacted a law to expand voters ability to vote early in elections` + `recentnewsState legislature enacted a law to expand voters ability to vote early in elections:pid3D` - `recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` - `recentnewsState legislature enacted a law to limit the right to protest at the state capitol building:pid3D` = 0"))

# among Republican respondents, limit protest vs. expand protest
summary(glht(choice_model_pid_crse, 
             linfct = "`recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` - `recentnewsState legislature enacted a law to expand the right to protest at the state capitol building` = 0"))

# among Republican respondents, expand protest vs. limit voting
summary(glht(choice_model_pid_crse, 
             linfct = "`recentnewsState legislature enacted a law to expand the right to protest at the state capitol building` - `recentnewsState legislature enacted a law to limit voters ability to vote early in elections` = 0"))

# among Republican respondents, expand voting vs. limit voting
summary(glht(choice_model_pid_crse, 
             linfct = "`recentnewsState legislature enacted a law to expand voters ability to vote early in elections` - `recentnewsState legislature enacted a law to limit voters ability to vote early in elections` = 0"))

# among Republican respondents, expand voting vs. limit protest
summary(glht(choice_model_pid_crse, 
             linfct = "`recentnewsState legislature enacted a law to expand voters ability to vote early in elections` - `recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` = 0"))

################################################################################
################################################################################

# SUPPLEMENTAL INFORMATION

# TABLE SI.A1b

# every respondent has 30 observations (10 tasks x 3 profiles per task), so we
# subset such that we only have one observation per respondent
respondent_demos <- subset(study1_responses, select = c("ResponseId", "pid3",
                                                          "gender", "income",
                                                          "age_bin", "educ",
                                                          "ideology", "white_nh",
                                                          "white_h", "black_nh",
                                                          "black_h", "asian",
                                                          "other"))

respondent_demos <- respondent_demos[!duplicated(respondent_demos),]

# gender
table(respondent_demos$gender, useNA = "always")
round(prop.table(table(respondent_demos$gender)),3)*100

# age (binned)
table(respondent_demos$age_bin, useNA = "always")
round(prop.table(table(respondent_demos$age_bin)),3)*100

# race/ethnicity.  Please note that respondent_demos who are not recorded as a 1 for
# any of the categories (provided from Lucid directly) are coded as missing;
# because this affects the denominator, percentages must be calculated manually
# rather than with prop.table
table(respondent_demos$white_nh, useNA = "always")
round(table(respondent_demos$white_nh, useNA = "always")/dim(respondent_demos)[1],3)*100
table(respondent_demos$white_h, useNA = "always")
round(table(respondent_demos$white_h, useNA = "always")/dim(respondent_demos)[1],3)*100
table(respondent_demos$black_nh, useNA = "always")
round(table(respondent_demos$black_nh, useNA = "always")/dim(respondent_demos)[1],3)*100
table(respondent_demos$black_h, useNA = "always")
round(table(respondent_demos$black_h, useNA = "always")/dim(respondent_demos)[1],3)*100
table(respondent_demos$asian, useNA = "always")
round(table(respondent_demos$asian, useNA = "always")/dim(respondent_demos)[1],3)*100
table(respondent_demos$other, useNA = "always")
round(table(respondent_demos$other, useNA = "always")/dim(respondent_demos)[1],3)*100
table(respondent_demos$white_nh==0 &
        respondent_demos$white_h==0 &
        respondent_demos$black_nh==0 &
        respondent_demos$black_h==0 &
        respondent_demos$asian==0 &
        respondent_demos$other==0, useNA = "always")
round(table(respondent_demos$white_nh==0 &
              respondent_demos$white_h==0 &
              respondent_demos$black_nh==0 &
              respondent_demos$black_h==0 &
              respondent_demos$asian==0 &
              respondent_demos$other==0, useNA = "always")/dim(respondent_demos)[1],3)*100

# education
table(respondent_demos$educ, useNA = "always")
round(prop.table(table(respondent_demos$educ, useNA = "always")),3)*100

# income
table(respondent_demos$income, useNA = "always")
round(prop.table(table(respondent_demos$income, useNA = "always")),3)*100

# party identification (collapsed from a 7-point scale to include leaners with
# the parties they lean towards)
table(respondent_demos$pid3, useNA = "always")
round(prop.table(table(respondent_demos$pid3)),3)*100

# ideology
table(respondent_demos$ideology, useNA = "always")
round(prop.table(table(respondent_demos$ideology, useNA = "always")),3)*100

################################################################################

# In-text at the beginning of Section SI.B, we note that "The substantive 
# interpretation of our findings is consistent across both experiments when we use
# information about attention check passage to calculate complier average treatment
# effects."  We provide the code here to estimate complier average treatment effects
# for the analyses that underlie our main results (Figure 1/Table SI.3).

# We calculate the CACEs when respondents who passed at least one attention check
# are considered treated and when only respondents who passed both attention 
# checks are treated; these CACEs represent the lower and upper bounds of the
# true CACE (Gerber and Green 2012, pgs. 164-165).

# CACEs calculated using instrumental variables approach/two-stage least squares
# with feols, which can only accommodate one treatment at a time.  Given that we
# are primarily interested in the levels of the Recent News attribute, we provide
# analyses that only include the unique levels of that attribute compared
# to the baseline and omit all other attributes, and conduct separate analyses
# for each non-baseline level compared to the baseline level.

# Please note that the general substantive results from our main analysis--that
# destinations in states that have recently backslid are less likely to be chosen
# than states that have not recently backslid for the full sample and
# among Democrats--persist.

# recoding attribute-levels as binary indicators and incorporating attentiveness

study1_responses$restrict_voting <- ifelse(study1_responses$recentnews=="State legislature enacted a law to limit voters ability to vote early in elections", 1, 0)
study1_responses$restrict_voting_att1 <- ifelse(study1_responses$recentnews=="State legislature enacted a law to limit voters ability to vote early in elections" & study1_responses$attentiveness>=1, 1, 0)
study1_responses$restrict_voting_att2 <- ifelse(study1_responses$recentnews=="State legislature enacted a law to limit voters ability to vote early in elections" & study1_responses$attentiveness>=2, 1, 0)
study1_responses$expand_voting <- ifelse(study1_responses$recentnews=="State legislature enacted a law to expand voters ability to vote early in elections", 1, 0)
study1_responses$expand_voting_att1 <- ifelse(study1_responses$recentnews=="State legislature enacted a law to expand voters ability to vote early in elections" & study1_responses$attentiveness>=1, 1, 0)
study1_responses$expand_voting_att2 <- ifelse(study1_responses$recentnews=="State legislature enacted a law to expand voters ability to vote early in elections" & study1_responses$attentiveness>=2, 1, 0)
study1_responses$restrict_protest <- ifelse(study1_responses$recentnews=="State legislature enacted a law to limit the right to protest at the state capitol building", 1, 0)
study1_responses$restrict_protest_att1 <- ifelse(study1_responses$recentnews=="State legislature enacted a law to limit the right to protest at the state capitol building" & study1_responses$attentiveness>=1, 1, 0)
study1_responses$restrict_protest_att2 <- ifelse(study1_responses$recentnews=="State legislature enacted a law to limit the right to protest at the state capitol building" & study1_responses$attentiveness>=2, 1, 0)
study1_responses$expand_protest <- ifelse(study1_responses$recentnews=="State legislature enacted a law to expand the right to protest at the state capitol building", 1, 0)
study1_responses$expand_protest_att1 <- ifelse(study1_responses$recentnews=="State legislature enacted a law to expand the right to protest at the state capitol building" & study1_responses$attentiveness>=1, 1, 0)
study1_responses$expand_protest_att2 <- ifelse(study1_responses$recentnews=="State legislature enacted a law to expand the right to protest at the state capitol building" & study1_responses$attentiveness>=1, 2, 0)

# CACEs among all respondents

choice_model_iv_restrict_voting_att1 <- feols(choice ~ 1 | restrict_voting_att1 ~ restrict_voting, 
                                              cluster = "ResponseId", data = study1_responses[which(study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                        study1_responses$recentnews=="State legislature enacted a law to limit voters ability to vote early in elections"),])
summary(choice_model_iv_restrict_voting_att1)
choice_model_iv_restrict_voting_att2 <- feols(choice ~ 1 | restrict_voting_att2 ~ restrict_voting, 
                                              cluster = "ResponseId", data = study1_responses[which(study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                        study1_responses$recentnews=="State legislature enacted a law to limit voters ability to vote early in elections"),])
summary(choice_model_iv_restrict_voting_att2)
choice_model_iv_expand_voting_att1 <- feols(choice ~ 1 | expand_voting_att1 ~ expand_voting, 
                                              cluster = "ResponseId", data = study1_responses[which(study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                        study1_responses$recentnews=="State legislature enacted a law to expand voters ability to vote early in elections"),])
summary(choice_model_iv_expand_voting_att1)
choice_model_iv_expand_voting_att2 <- feols(choice ~ 1 | expand_voting_att2 ~ expand_voting, 
                                              cluster = "ResponseId", data = study1_responses[which(study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                        study1_responses$recentnews=="State legislature enacted a law to expand voters ability to vote early in elections"),])
summary(choice_model_iv_expand_voting_att2)
choice_model_iv_restrict_protest_att1 <- feols(choice ~ 1 | restrict_protest_att1 ~ restrict_protest, 
                                              cluster = "ResponseId", data = study1_responses[which(study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                        study1_responses$recentnews=="State legislature enacted a law to limit the right to protest at the state capitol building"),])
summary(choice_model_iv_restrict_protest_att1)
choice_model_iv_restrict_protest_att2 <- feols(choice ~ 1 | restrict_protest_att2 ~ restrict_protest, 
                                              cluster = "ResponseId", data = study1_responses[which(study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                        study1_responses$recentnews=="State legislature enacted a law to limit the right to protest at the state capitol building"),])
summary(choice_model_iv_restrict_protest_att2)
choice_model_iv_expand_protest_att1 <- feols(choice ~ 1 | expand_protest_att1 ~ expand_protest, 
                                            cluster = "ResponseId", data = study1_responses[which(study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                      study1_responses$recentnews=="State legislature enacted a law to expand the right to protest at the state capitol building"),])
summary(choice_model_iv_expand_protest_att1)
choice_model_iv_expand_protest_att2 <- feols(choice ~ 1 | expand_protest_att2 ~ expand_protest, 
                                            cluster = "ResponseId", data = study1_responses[which(study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                      study1_responses$recentnews=="State legislature enacted a law to expand the right to protest at the state capitol building"),])
summary(choice_model_iv_expand_protest_att2)

# CACEs among Democrats

choice_model_iv_D_restrict_voting_att1 <- feols(choice ~ 1 | restrict_voting_att1 ~ restrict_voting, 
                                              cluster = "ResponseId", data = study1_responses[which(study1_responses$pid3=="D" &
                                                                                                        (study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                             study1_responses$recentnews=="State legislature enacted a law to limit voters ability to vote early in elections"))])
summary(choice_model_iv_D_restrict_voting_att1)
choice_model_iv_D_restrict_voting_att2 <- feols(choice ~ 1 | restrict_voting_att2 ~ restrict_voting, 
                                                cluster = "ResponseId", data = study1_responses[which(study1_responses$pid3=="D" & 
                                                                                                          (study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                               study1_responses$recentnews=="State legislature enacted a law to limit voters ability to vote early in elections"))])
summary(choice_model_iv_D_restrict_voting_att2)
choice_model_iv_D_expand_voting_att1 <- feols(choice ~ 1 | expand_voting_att1 ~ expand_voting, 
                                              cluster = "ResponseId", data = study1_responses[which(study1_responses$pid3=="D" &
                                                                                                        (study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                             study1_responses$recentnews=="State legislature enacted a law to expand voters ability to vote early in elections"))])
summary(choice_model_iv_D_expand_voting_att1)
choice_model_iv_D_expand_voting_att2 <- feols(choice ~ 1 | expand_voting_att2 ~ expand_voting, 
                                              cluster = "ResponseId", data = study1_responses[which(study1_responses$pid3=="D" &
                                                                                                        (study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                             study1_responses$recentnews=="State legislature enacted a law to expand voters ability to vote early in elections"))])
summary(choice_model_iv_D_expand_voting_att2)
choice_model_iv_D_restrict_protest_att1 <- feols(choice ~ 1 | restrict_protest_att1 ~ restrict_protest, 
                                                 cluster = "ResponseId", data = study1_responses[which(study1_responses$pid3=="D" &
                                                                                                           (study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                                study1_responses$recentnews=="State legislature enacted a law to limit the right to protest at the state capitol building"))])
summary(choice_model_iv_D_restrict_protest_att1)
choice_model_iv_D_restrict_protest_att2 <- feols(choice ~ 1 | restrict_protest_att2 ~ restrict_protest, 
                                                 cluster = "ResponseId", data = study1_responses[which(study1_responses$pid3=="D" & 
                                                                                                           (study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                                study1_responses$recentnews=="State legislature enacted a law to limit the right to protest at the state capitol building"))])
summary(choice_model_iv_D_restrict_protest_att2)
choice_model_iv_D_expand_protest_att1 <- feols(choice ~ 1 | expand_protest_att1 ~ expand_protest, 
                                               cluster = "ResponseId", data = study1_responses[which(study1_responses$pid3=="D" &
                                                                                                         (study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                              study1_responses$recentnews=="State legislature enacted a law to expand the right to protest at the state capitol building"))])
summary(choice_model_iv_D_expand_protest_att1)
choice_model_iv_D_expand_protest_att2 <- feols(choice ~ 1 | expand_protest_att2 ~ expand_protest, 
                                               cluster = "ResponseId", data = study1_responses[which(study1_responses$pid3=="D" &
                                                                                                         (study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                              study1_responses$recentnews=="State legislature enacted a law to expand the right to protest at the state capitol building"))])
summary(choice_model_iv_D_expand_protest_att2)

# CACEs among Republicans

choice_model_iv_R_restrict_voting_att1 <- feols(choice ~ 1 | restrict_voting_att1 ~ restrict_voting, 
                                                cluster = "ResponseId", data = study1_responses[which(study1_responses$pid3=="R" &
                                                                                                          (study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                               study1_responses$recentnews=="State legislature enacted a law to limit voters ability to vote early in elections"))])
summary(choice_model_iv_R_restrict_voting_att1)
choice_model_iv_R_restrict_voting_att2 <- feols(choice ~ 1 | restrict_voting_att2 ~ restrict_voting, 
                                                cluster = "ResponseId", data = study1_responses[which(study1_responses$pid3=="R" & 
                                                                                                          (study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                               study1_responses$recentnews=="State legislature enacted a law to limit voters ability to vote early in elections"))])
summary(choice_model_iv_R_restrict_voting_att2)
choice_model_iv_R_expand_voting_att1 <- feols(choice ~ 1 | expand_voting_att1 ~ expand_voting, 
                                              cluster = "ResponseId", data = study1_responses[which(study1_responses$pid3=="R" &
                                                                                                        (study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                             study1_responses$recentnews=="State legislature enacted a law to expand voters ability to vote early in elections"))])
summary(choice_model_iv_R_expand_voting_att1)
choice_model_iv_R_expand_voting_att2 <- feols(choice ~ 1 | expand_voting_att2 ~ expand_voting, 
                                              cluster = "ResponseId", data = study1_responses[which(study1_responses$pid3=="R" &
                                                                                                        (study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                             study1_responses$recentnews=="State legislature enacted a law to expand voters ability to vote early in elections"))])
summary(choice_model_iv_R_expand_voting_att2)
choice_model_iv_R_restrict_protest_att1 <- feols(choice ~ 1 | restrict_protest_att1 ~ restrict_protest, 
                                                 cluster = "ResponseId", data = study1_responses[which(study1_responses$pid3=="R" &
                                                                                                           (study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                                study1_responses$recentnews=="State legislature enacted a law to limit the right to protest at the state capitol building"))])
summary(choice_model_iv_R_restrict_protest_att1)
choice_model_iv_R_restrict_protest_att2 <- feols(choice ~ 1 | restrict_protest_att2 ~ restrict_protest, 
                                                 cluster = "ResponseId", data = study1_responses[which(study1_responses$pid3=="R" & 
                                                                                                           (study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                                study1_responses$recentnews=="State legislature enacted a law to limit the right to protest at the state capitol building"))])
summary(choice_model_iv_R_restrict_protest_att2)
choice_model_iv_R_expand_protest_att1 <- feols(choice ~ 1 | expand_protest_att1 ~ expand_protest, 
                                               cluster = "ResponseId", data = study1_responses[which(study1_responses$pid3=="R" &
                                                                                                         (study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                              study1_responses$recentnews=="State legislature enacted a law to expand the right to protest at the state capitol building"))])
summary(choice_model_iv_R_expand_protest_att1)
choice_model_iv_R_expand_protest_att2 <- feols(choice ~ 1 | expand_protest_att2 ~ expand_protest, 
                                               cluster = "ResponseId", data = study1_responses[which(study1_responses$pid3=="R" &
                                                                                                         (study1_responses$recentnews=="State legislature formed a commission to study ways to stimulate economic growth" |
                                                                                                              study1_responses$recentnews=="State legislature enacted a law to expand the right to protest at the state capitol building"))])
summary(choice_model_iv_R_expand_protest_att2)

################################################################################

# TABLE SI.3

# among all respondents
# AMCEs
round(c(0,
        choice_model_crse$coefficients["recentnewsState legislature enacted a law to expand the right to protest at the state capitol building"],
        choice_model_crse$coefficients["recentnewsState legislature enacted a law to expand voters ability to vote early in elections"],
        choice_model_crse$coefficients["recentnewsState legislature enacted a law to limit the right to protest at the state capitol building"],
        choice_model_crse$coefficients["recentnewsState legislature enacted a law to limit voters ability to vote early in elections"],
        0,
        choice_model_crse$coefficients["temp67"],
        choice_model_crse$coefficients["temp72"],
        choice_model_crse$coefficients["temp78"],
        0,
        choice_model_crse$coefficients["communitySuburban"],
        choice_model_crse$coefficients["communityUrban"],
        0,
        choice_model_crse$coefficients["attractionsBeaches"],
        choice_model_crse$coefficients["attractionsMuseums"],
        choice_model_crse$coefficients["attractionsNational parks"],
        choice_model_crse$coefficients["attractionsSporting events"],
        choice_model_crse$coefficients["attractionsTheaters"],
        0,
        choice_model_crse$coefficients["traveltime2-4 hours"],
        choice_model_crse$coefficients["traveltime4-6 hours"],
        choice_model_crse$coefficients["traveltimeMore than 6 hours"],
        0,
        choice_model_crse$coefficients["preselecDonald Trump won by a small margin"],
        choice_model_crse$coefficients["preselecJoe Biden won by a small margin"],
        choice_model_crse$coefficients["preselecJoe Biden won by a large margin"]),2)
# AMCE 95% lower bound
round(c(0,
        confint(choice_model_crse)["recentnewsState legislature enacted a law to expand the right to protest at the state capitol building",1],
        confint(choice_model_crse)["recentnewsState legislature enacted a law to expand voters ability to vote early in elections",1],
        confint(choice_model_crse)["recentnewsState legislature enacted a law to limit the right to protest at the state capitol building",1],
        confint(choice_model_crse)["recentnewsState legislature enacted a law to limit voters ability to vote early in elections",1],
        0,
        confint(choice_model_crse)["temp67",1],
        confint(choice_model_crse)["temp72",1],
        confint(choice_model_crse)["temp78",1],
        0,
        confint(choice_model_crse)["communitySuburban",1],
        confint(choice_model_crse)["communityUrban",1],
        0,
        confint(choice_model_crse)["attractionsBeaches",1],
        confint(choice_model_crse)["attractionsMuseums",1],
        confint(choice_model_crse)["attractionsNational parks",1],
        confint(choice_model_crse)["attractionsSporting events",1],
        confint(choice_model_crse)["attractionsTheaters",1],
        0,
        confint(choice_model_crse)["traveltime2-4 hours",1],
        confint(choice_model_crse)["traveltime4-6 hours",1],
        confint(choice_model_crse)["traveltimeMore than 6 hours",1],
        0,
        confint(choice_model_crse)["preselecDonald Trump won by a small margin",1],
        confint(choice_model_crse)["preselecJoe Biden won by a small margin",1],
        confint(choice_model_crse)["preselecJoe Biden won by a large margin",1]),2)
# AMCE 95% upper bound
round(c(0,
        confint(choice_model_crse)["recentnewsState legislature enacted a law to expand the right to protest at the state capitol building",2],
        confint(choice_model_crse)["recentnewsState legislature enacted a law to expand voters ability to vote early in elections",2],
        confint(choice_model_crse)["recentnewsState legislature enacted a law to limit the right to protest at the state capitol building",2],
        confint(choice_model_crse)["recentnewsState legislature enacted a law to limit voters ability to vote early in elections",2],
        0,
        confint(choice_model_crse)["temp67",2],
        confint(choice_model_crse)["temp72",2],
        confint(choice_model_crse)["temp78",2],
        0,
        confint(choice_model_crse)["communitySuburban",2],
        confint(choice_model_crse)["communityUrban",2],
        0,
        confint(choice_model_crse)["attractionsBeaches",2],
        confint(choice_model_crse)["attractionsMuseums",2],
        confint(choice_model_crse)["attractionsNational parks",2],
        confint(choice_model_crse)["attractionsSporting events",2],
        confint(choice_model_crse)["attractionsTheaters",2],
        0,
        confint(choice_model_crse)["traveltime2-4 hours",2],
        confint(choice_model_crse)["traveltime4-6 hours",2],
        confint(choice_model_crse)["traveltimeMore than 6 hours",2],
        0,
        confint(choice_model_crse)["preselecDonald Trump won by a small margin",2],
        confint(choice_model_crse)["preselecJoe Biden won by a small margin",2],
        confint(choice_model_crse)["preselecJoe Biden won by a large margin",2]),2)

# among Democrats only

# ACIEs
round(c(0,
        recentnewsExpandProtest_choice_D$confint[,"Estimate"],
        recentnewsExpandEarlyVoting_choice_D$confint[,"Estimate"],
        recentnewsLimitProtest_choice_D$confint[,"Estimate"],
        recentnewsLimitEarlyVoting_choice_D$confint[,"Estimate"],
        0,
        temp67_choice_D$confint[,"Estimate"],
        temp72_choice_D$confint[,"Estimate"],
        temp78_choice_D$confint[,"Estimate"],
        0,
        communitySuburban_choice_D$confint[,"Estimate"],
        communityUrban_choice_D$confint[,"Estimate"],
        0,
        attractionsBeaches_choice_D$confint[,"Estimate"],
        attractionsMuseums_choice_D$confint[,"Estimate"],
        attractionsParks_choice_D$confint[,"Estimate"],
        attractionsSports_choice_D$confint[,"Estimate"],
        attractionsTheaters_choice_D$confint[,"Estimate"],
        0,
        traveltime2to4hours_choice_D$confint[,"Estimate"],
        traveltime4to6hours_choice_D$confint[,"Estimate"],
        traveltime6Plushours_choice_D$confint[,"Estimate"],
        0,
        preselecSmallTrumpMargin_choice_D$confint[,"Estimate"],
        preselecSmallBidenMargin_choice_D$confint[,"Estimate"],
        preselecLargeBidenMargin_choice_D$confint[,"Estimate"]),2)

# ACIE 95% lower bound
round(c(0,
        recentnewsExpandProtest_choice_D$confint[,"lwr"],
        recentnewsExpandEarlyVoting_choice_D$confint[,"lwr"],
        recentnewsLimitProtest_choice_D$confint[,"lwr"],
        recentnewsLimitEarlyVoting_choice_D$confint[,"lwr"],
        0,
        temp67_choice_D$confint[,"lwr"],
        temp72_choice_D$confint[,"lwr"],
        temp78_choice_D$confint[,"lwr"],
        0,
        communitySuburban_choice_D$confint[,"lwr"],
        communityUrban_choice_D$confint[,"lwr"],
        0,
        attractionsBeaches_choice_D$confint[,"lwr"],
        attractionsMuseums_choice_D$confint[,"lwr"],
        attractionsParks_choice_D$confint[,"lwr"],
        attractionsSports_choice_D$confint[,"lwr"],
        attractionsTheaters_choice_D$confint[,"lwr"],
        0,
        traveltime2to4hours_choice_D$confint[,"lwr"],
        traveltime4to6hours_choice_D$confint[,"lwr"],
        traveltime6Plushours_choice_D$confint[,"lwr"],
        0,
        preselecSmallTrumpMargin_choice_D$confint[,"lwr"],
        preselecSmallBidenMargin_choice_D$confint[,"lwr"],
        preselecLargeBidenMargin_choice_D$confint[,"lwr"]),2)

# ACIE 95% upper bound
round(c(0,
        recentnewsExpandProtest_choice_D$confint[,"upr"],
        recentnewsExpandEarlyVoting_choice_D$confint[,"upr"],
        recentnewsLimitProtest_choice_D$confint[,"upr"],
        recentnewsLimitEarlyVoting_choice_D$confint[,"upr"],
        0,
        temp67_choice_D$confint[,"upr"],
        temp72_choice_D$confint[,"upr"],
        temp78_choice_D$confint[,"upr"],
        0,
        communitySuburban_choice_D$confint[,"upr"],
        communityUrban_choice_D$confint[,"upr"],
        0,
        attractionsBeaches_choice_D$confint[,"upr"],
        attractionsMuseums_choice_D$confint[,"upr"],
        attractionsParks_choice_D$confint[,"upr"],
        attractionsSports_choice_D$confint[,"upr"],
        attractionsTheaters_choice_D$confint[,"upr"],
        0,
        traveltime2to4hours_choice_D$confint[,"upr"],
        traveltime4to6hours_choice_D$confint[,"upr"],
        traveltime6Plushours_choice_D$confint[,"upr"],
        0,
        preselecSmallTrumpMargin_choice_D$confint[,"upr"],
        preselecSmallBidenMargin_choice_D$confint[,"upr"],
        preselecLargeBidenMargin_choice_D$confint[,"upr"]),2)

# among Republicans only

# ACIEs
round(c(0,
        recentnewsExpandProtest_choice_R$confint[,"Estimate"],
        recentnewsExpandEarlyVoting_choice_R$confint[,"Estimate"],
        recentnewsLimitProtest_choice_R$confint[,"Estimate"],
        recentnewsLimitEarlyVoting_choice_R$confint[,"Estimate"],
        0,
        temp67_choice_R$confint[,"Estimate"],
        temp72_choice_R$confint[,"Estimate"],
        temp78_choice_R$confint[,"Estimate"],
        0,
        communitySuburban_choice_R$confint[,"Estimate"],
        communityUrban_choice_R$confint[,"Estimate"],
        0,
        attractionsBeaches_choice_R$confint[,"Estimate"],
        attractionsMuseums_choice_R$confint[,"Estimate"],
        attractionsParks_choice_R$confint[,"Estimate"],
        attractionsSports_choice_R$confint[,"Estimate"],
        attractionsTheaters_choice_R$confint[,"Estimate"],
        0,
        traveltime2to4hours_choice_R$confint[,"Estimate"],
        traveltime4to6hours_choice_R$confint[,"Estimate"],
        traveltime6Plushours_choice_R$confint[,"Estimate"],
        0,
        preselecSmallTrumpMargin_choice_R$confint[,"Estimate"],
        preselecSmallBidenMargin_choice_R$confint[,"Estimate"],
        preselecLargeBidenMargin_choice_R$confint[,"Estimate"]),2)

# ACIE 95% lower bound
round(c(0,
        recentnewsExpandProtest_choice_R$confint[,"lwr"],
        recentnewsExpandEarlyVoting_choice_R$confint[,"lwr"],
        recentnewsLimitProtest_choice_R$confint[,"lwr"],
        recentnewsLimitEarlyVoting_choice_R$confint[,"lwr"],
        0,
        temp67_choice_R$confint[,"lwr"],
        temp72_choice_R$confint[,"lwr"],
        temp78_choice_R$confint[,"lwr"],
        0,
        communitySuburban_choice_R$confint[,"lwr"],
        communityUrban_choice_R$confint[,"lwr"],
        0,
        attractionsBeaches_choice_R$confint[,"lwr"],
        attractionsMuseums_choice_R$confint[,"lwr"],
        attractionsParks_choice_R$confint[,"lwr"],
        attractionsSports_choice_R$confint[,"lwr"],
        attractionsTheaters_choice_R$confint[,"lwr"],
        0,
        traveltime2to4hours_choice_R$confint[,"lwr"],
        traveltime4to6hours_choice_R$confint[,"lwr"],
        traveltime6Plushours_choice_R$confint[,"lwr"],
        0,
        preselecSmallTrumpMargin_choice_R$confint[,"lwr"],
        preselecSmallBidenMargin_choice_R$confint[,"lwr"],
        preselecLargeBidenMargin_choice_R$confint[,"lwr"]),2)

# 95% ACIE upper bound
round(c(0,
        recentnewsExpandProtest_choice_R$confint[,"upr"],
        recentnewsExpandEarlyVoting_choice_R$confint[,"upr"],
        recentnewsLimitProtest_choice_R$confint[,"upr"],
        recentnewsLimitEarlyVoting_choice_R$confint[,"upr"],
        0,
        temp67_choice_R$confint[,"upr"],
        temp72_choice_R$confint[,"upr"],
        temp78_choice_R$confint[,"upr"],
        0,
        communitySuburban_choice_R$confint[,"upr"],
        communityUrban_choice_R$confint[,"upr"],
        0,
        attractionsBeaches_choice_R$confint[,"upr"],
        attractionsMuseums_choice_R$confint[,"upr"],
        attractionsParks_choice_R$confint[,"upr"],
        attractionsSports_choice_R$confint[,"upr"],
        attractionsTheaters_choice_R$confint[,"upr"],
        0,
        traveltime2to4hours_choice_R$confint[,"upr"],
        traveltime4to6hours_choice_R$confint[,"upr"],
        traveltime6Plushours_choice_R$confint[,"upr"],
        0,
        preselecSmallTrumpMargin_choice_R$confint[,"upr"],
        preselecSmallBidenMargin_choice_R$confint[,"upr"],
        preselecLargeBidenMargin_choice_R$confint[,"upr"]),2)

# n for all respondents, # of all respondents
sum(table(study1_responses$choice, useNA = "always")[1:2])
length(unique(study1_responses$ResponseId[!is.na(study1_responses$choice)]))

# n for democrats, # of democrats
sum(table(study1_responses$choice[which(study1_responses$pid3=="D")], useNA = "always")[1:2])
length(unique(study1_responses$ResponseId[!is.na(study1_responses$choice) & study1_responses$pid3=="D"]))

# n for republicans, # of republicans
sum(table(study1_responses$choice[which(study1_responses$pid3=="R")], useNA = "always")[1:2])
length(unique(study1_responses$ResponseId[!is.na(study1_responses$choice) & study1_responses$pid3=="R"]))

################################################################################

# TABLE SI.4

# AMCEs among all respondents (rating outcome)
rating_model <- lm(rating ~ temp + attractions + traveltime + preselec + recentnews + community,
                   data = study1_responses)
# calculating variance-covariance matrix for cluster robust SEs (clustered on respondent)
rating_model_vcov <- cluster.vcov(rating_model, cluster = study1_responses$ResponseId)
# model summary with CRSEs
coeftest(rating_model, rating_model_vcov)
# saving SEs, p-values, and the cariance-covariance matrix
rating_model_vcov_ses <- coeftest(rating_model, rating_model_vcov)[,2]
rating_model_vcov_pvals <- coeftest(rating_model, rating_model_vcov)[,4]
rating_model_crse <- withVCov(rating_model, rating_model_vcov)

# ACIEs among Democrats and Republicans (choice outcome)
# model conditions every non-baseline attribute level on PID (1 if Democrat, 0
# if Republican); ACIEs are then calculated from estimated coefficients using
# glht from the multcomp package (for Republicans, coefficients for 
# attribute-levels themselves are used; for Democrats, the combination of the 
# coefficients from the attribute-levels themselves AND the corresponding terms 
# that interact PID and attribute-levels are used)
rating_model_pid <- lm(rating ~ temp + attractions + traveltime + 
                         preselec + recentnews + community + pid3 +
                         temp:pid3 + attractions:pid3 + traveltime:pid3 + 
                         preselec:pid3 + recentnews:pid3 + community:pid3,
                       data = study1_responses[which(study1_responses$pid3=="D" |
                                                        study1_responses$pid3=="R")])
# calculating variance-covariance matrix for cluster robust SEs (clustered on respondent)
rating_model_pid_vcov <- cluster.vcov(rating_model_pid, cluster = study1_responses$ResponseId[which(study1_responses$pid3=="D" |
                                                                                                       study1_responses$pid3=="R")])
# model summary with CRSEs
coeftest(rating_model_pid, rating_model_pid_vcov)
# saving SEs, p-values, and the cariance-covariance matrix
rating_model_pid_vcov_ses <- coeftest(rating_model_pid, rating_model_pid_vcov)[,2]
rating_model_pid_vcov_pvals <- coeftest(rating_model_pid, rating_model_pid_vcov)[,4]
rating_model_pid_crse <- withVCov(rating_model_pid, rating_model_pid_vcov)

# as when obtaining the ACIEs for the choice outcome, we use glht to extract the
# point estimates and 95% confidence intervals for Democrats and Republicans

# ACIEs for Democrats (rating outcome)
temp67_rating_D <- confint(glht(rating_model_pid_crse, linfct = "temp67 + temp67:pid3D = 0"))
temp72_rating_D <- confint(glht(rating_model_pid_crse, linfct = "temp72 + temp72:pid3D = 0"))
temp78_rating_D <- confint(glht(rating_model_pid_crse, linfct = "temp78 + temp78:pid3D = 0"))
communitySuburban_rating_D <- confint(glht(rating_model_pid_crse, linfct = "communitySuburban + communitySuburban:pid3D = 0"))
communityUrban_rating_D <- confint(glht(rating_model_pid_crse, linfct = "communityUrban + communityUrban:pid3D = 0"))
attractionsBeaches_rating_D <- confint(glht(rating_model_pid_crse, linfct = "attractionsBeaches + attractionsBeaches:pid3D = 0"))
attractionsMuseums_rating_D <- confint(glht(rating_model_pid_crse, linfct = "attractionsMuseums + attractionsMuseums:pid3D = 0"))
attractionsParks_rating_D <- confint(glht(rating_model_pid_crse, linfct = "`attractionsNational parks` + `attractionsNational parks:pid3D` = 0"))
attractionsSports_rating_D <- confint(glht(rating_model_pid_crse, linfct = "`attractionsSporting events` + `attractionsSporting events:pid3D` = 0"))
attractionsTheaters_rating_D <- confint(glht(rating_model_pid_crse, linfct = "attractionsTheaters + attractionsTheaters:pid3D = 0"))
traveltime2to4hours_rating_D <- confint(glht(rating_model_pid_crse, linfct = "`traveltime2-4 hours` + `traveltime2-4 hours:pid3D` = 0"))
traveltime4to6hours_rating_D <- confint(glht(rating_model_pid_crse, linfct = "`traveltime4-6 hours` + `traveltime4-6 hours:pid3D` = 0"))
traveltime6Plushours_rating_D <- confint(glht(rating_model_pid_crse, linfct = "`traveltimeMore than 6 hours` + `traveltimeMore than 6 hours:pid3D` = 0"))
preselecSmallTrumpMargin_rating_D <- confint(glht(rating_model_pid_crse, linfct = "`preselecDonald Trump won by a small margin` + `preselecDonald Trump won by a small margin:pid3D` = 0"))
preselecSmallBidenMargin_rating_D <- confint(glht(rating_model_pid_crse, linfct = "`preselecJoe Biden won by a small margin` + `preselecJoe Biden won by a small margin:pid3D` = 0"))
preselecLargeBidenMargin_rating_D <- confint(glht(rating_model_pid_crse, linfct = "`preselecJoe Biden won by a large margin` + `preselecJoe Biden won by a large margin:pid3D` = 0"))
recentnewsExpandProtest_rating_D <- confint(glht(rating_model_pid_crse, linfct = "`recentnewsState legislature enacted a law to expand the right to protest at the state capitol building` + `recentnewsState legislature enacted a law to expand the right to protest at the state capitol building:pid3D` = 0"))
recentnewsExpandEarlyVoting_rating_D <- confint(glht(rating_model_pid_crse, linfct = "`recentnewsState legislature enacted a law to expand voters ability to vote early in elections` + `recentnewsState legislature enacted a law to expand voters ability to vote early in elections:pid3D` = 0"))
recentnewsLimitProtest_rating_D <- confint(glht(rating_model_pid_crse, linfct = "`recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` + `recentnewsState legislature enacted a law to limit the right to protest at the state capitol building:pid3D` = 0"))
recentnewsLimitEarlyVoting_rating_D <- confint(glht(rating_model_pid_crse, linfct = "`recentnewsState legislature enacted a law to limit voters ability to vote early in elections` + `recentnewsState legislature enacted a law to limit voters ability to vote early in elections:pid3D` = 0"))

# ACIEs for Republicans (rating outcome)
temp67_rating_R <- confint(glht(rating_model_pid_crse, linfct = "temp67 = 0"))
temp72_rating_R <- confint(glht(rating_model_pid_crse, linfct = "temp72 = 0"))
temp78_rating_R <- confint(glht(rating_model_pid_crse, linfct = "temp78 = 0"))
communitySuburban_rating_R <- confint(glht(rating_model_pid_crse, linfct = "communitySuburban = 0"))
communityUrban_rating_R <- confint(glht(rating_model_pid_crse, linfct = "communityUrban = 0"))
attractionsBeaches_rating_R <- confint(glht(rating_model_pid_crse, linfct = "attractionsBeaches = 0"))
attractionsMuseums_rating_R <- confint(glht(rating_model_pid_crse, linfct = "attractionsMuseums = 0"))
attractionsParks_rating_R <- confint(glht(rating_model_pid_crse, linfct = "`attractionsNational parks` = 0"))
attractionsSports_rating_R <- confint(glht(rating_model_pid_crse, linfct = "`attractionsSporting events` = 0"))
attractionsTheaters_rating_R <- confint(glht(rating_model_pid_crse, linfct = "attractionsTheaters = 0"))
traveltime2to4hours_rating_R <- confint(glht(rating_model_pid_crse, linfct = "`traveltime2-4 hours` = 0"))
traveltime4to6hours_rating_R <- confint(glht(rating_model_pid_crse, linfct = "`traveltime4-6 hours` = 0"))
traveltime6Plushours_rating_R <- confint(glht(rating_model_pid_crse, linfct = "`traveltimeMore than 6 hours` = 0"))
preselecSmallTrumpMargin_rating_R <- confint(glht(rating_model_pid_crse, linfct = "`preselecDonald Trump won by a small margin` = 0"))
preselecSmallBidenMargin_rating_R <- confint(glht(rating_model_pid_crse, linfct = "`preselecJoe Biden won by a small margin` = 0"))
preselecLargeBidenMargin_rating_R <- confint(glht(rating_model_pid_crse, linfct = "`preselecJoe Biden won by a large margin` = 0"))
recentnewsExpandProtest_rating_R <- confint(glht(rating_model_pid_crse, linfct = "`recentnewsState legislature enacted a law to expand the right to protest at the state capitol building` = 0"))
recentnewsExpandEarlyVoting_rating_R <- confint(glht(rating_model_pid_crse, linfct = "`recentnewsState legislature enacted a law to expand voters ability to vote early in elections` = 0"))
recentnewsLimitProtest_rating_R <- confint(glht(rating_model_pid_crse, linfct = "`recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` = 0"))
recentnewsLimitEarlyVoting_rating_R <- confint(glht(rating_model_pid_crse, linfct = "`recentnewsState legislature enacted a law to limit voters ability to vote early in elections`= 0"))

# AMCEs among all respondents
round(c(0,
        rating_model_crse$coefficients["recentnewsState legislature enacted a law to expand the right to protest at the state capitol building"],
        rating_model_crse$coefficients["recentnewsState legislature enacted a law to expand voters ability to vote early in elections"],
        rating_model_crse$coefficients["recentnewsState legislature enacted a law to limit the right to protest at the state capitol building"],
        rating_model_crse$coefficients["recentnewsState legislature enacted a law to limit voters ability to vote early in elections"],
        0,
        rating_model_crse$coefficients["temp67"],
        rating_model_crse$coefficients["temp72"],
        rating_model_crse$coefficients["temp78"],
        0,
        rating_model_crse$coefficients["communitySuburban"],
        rating_model_crse$coefficients["communityUrban"],
        0,
        rating_model_crse$coefficients["attractionsBeaches"],
        rating_model_crse$coefficients["attractionsMuseums"],
        rating_model_crse$coefficients["attractionsNational parks"],
        rating_model_crse$coefficients["attractionsSporting events"],
        rating_model_crse$coefficients["attractionsTheaters"],
        0,
        rating_model_crse$coefficients["traveltime2-4 hours"],
        rating_model_crse$coefficients["traveltime4-6 hours"],
        rating_model_crse$coefficients["traveltimeMore than 6 hours"],
        0,
        rating_model_crse$coefficients["preselecDonald Trump won by a small margin"],
        rating_model_crse$coefficients["preselecJoe Biden won by a small margin"],
        rating_model_crse$coefficients["preselecJoe Biden won by a large margin"]),2)
# AMCE 95% lower bound
round(c(0,
        confint(rating_model_crse)["recentnewsState legislature enacted a law to expand the right to protest at the state capitol building",1],
        confint(rating_model_crse)["recentnewsState legislature enacted a law to expand voters ability to vote early in elections",1],
        confint(rating_model_crse)["recentnewsState legislature enacted a law to limit the right to protest at the state capitol building",1],
        confint(rating_model_crse)["recentnewsState legislature enacted a law to limit voters ability to vote early in elections",1],
        0,
        confint(rating_model_crse)["temp67",1],
        confint(rating_model_crse)["temp72",1],
        confint(rating_model_crse)["temp78",1],
        0,
        confint(rating_model_crse)["communitySuburban",1],
        confint(rating_model_crse)["communityUrban",1],
        0,
        confint(rating_model_crse)["attractionsBeaches",1],
        confint(rating_model_crse)["attractionsMuseums",1],
        confint(rating_model_crse)["attractionsNational parks",1],
        confint(rating_model_crse)["attractionsSporting events",1],
        confint(rating_model_crse)["attractionsTheaters",1],
        0,
        confint(rating_model_crse)["traveltime2-4 hours",1],
        confint(rating_model_crse)["traveltime4-6 hours",1],
        confint(rating_model_crse)["traveltimeMore than 6 hours",1],
        0,
        confint(rating_model_crse)["preselecDonald Trump won by a small margin",1],
        confint(rating_model_crse)["preselecJoe Biden won by a small margin",1],
        confint(rating_model_crse)["preselecJoe Biden won by a large margin",1]),2)
# AMCE 95% upper bound
round(c(0,
        confint(rating_model_crse)["recentnewsState legislature enacted a law to expand the right to protest at the state capitol building",2],
        confint(rating_model_crse)["recentnewsState legislature enacted a law to expand voters ability to vote early in elections",2],
        confint(rating_model_crse)["recentnewsState legislature enacted a law to limit the right to protest at the state capitol building",2],
        confint(rating_model_crse)["recentnewsState legislature enacted a law to limit voters ability to vote early in elections",2],
        0,
        confint(rating_model_crse)["temp67",2],
        confint(rating_model_crse)["temp72",2],
        confint(rating_model_crse)["temp78",2],
        0,
        confint(rating_model_crse)["communitySuburban",2],
        confint(rating_model_crse)["communityUrban",2],
        0,
        confint(rating_model_crse)["attractionsBeaches",2],
        confint(rating_model_crse)["attractionsMuseums",2],
        confint(rating_model_crse)["attractionsNational parks",2],
        confint(rating_model_crse)["attractionsSporting events",2],
        confint(rating_model_crse)["attractionsTheaters",2],
        0,
        confint(rating_model_crse)["traveltime2-4 hours",2],
        confint(rating_model_crse)["traveltime4-6 hours",2],
        confint(rating_model_crse)["traveltimeMore than 6 hours",2],
        0,
        confint(rating_model_crse)["preselecDonald Trump won by a small margin",2],
        confint(rating_model_crse)["preselecJoe Biden won by a small margin",2],
        confint(rating_model_crse)["preselecJoe Biden won by a large margin",2]),2)

# among Democrats only

# ACIEs
round(c(0,
        recentnewsExpandProtest_rating_D$confint[,"Estimate"],
        recentnewsExpandEarlyVoting_rating_D$confint[,"Estimate"],
        recentnewsLimitProtest_rating_D$confint[,"Estimate"],
        recentnewsLimitEarlyVoting_rating_D$confint[,"Estimate"],
        0,
        temp67_rating_D$confint[,"Estimate"],
        temp72_rating_D$confint[,"Estimate"],
        temp78_rating_D$confint[,"Estimate"],
        0,
        communitySuburban_rating_D$confint[,"Estimate"],
        communityUrban_rating_D$confint[,"Estimate"],
        0,
        attractionsBeaches_rating_D$confint[,"Estimate"],
        attractionsMuseums_rating_D$confint[,"Estimate"],
        attractionsParks_rating_D$confint[,"Estimate"],
        attractionsSports_rating_D$confint[,"Estimate"],
        attractionsTheaters_rating_D$confint[,"Estimate"],
        0,
        traveltime2to4hours_rating_D$confint[,"Estimate"],
        traveltime4to6hours_rating_D$confint[,"Estimate"],
        traveltime6Plushours_rating_D$confint[,"Estimate"],
        0,
        preselecSmallTrumpMargin_rating_D$confint[,"Estimate"],
        preselecSmallBidenMargin_rating_D$confint[,"Estimate"],
        preselecLargeBidenMargin_rating_D$confint[,"Estimate"]),2)

# ACIE 95% lower bound
round(c(0,
        recentnewsExpandProtest_rating_D$confint[,"lwr"],
        recentnewsExpandEarlyVoting_rating_D$confint[,"lwr"],
        recentnewsLimitProtest_rating_D$confint[,"lwr"],
        recentnewsLimitEarlyVoting_rating_D$confint[,"lwr"],
        0,
        temp67_rating_D$confint[,"lwr"],
        temp72_rating_D$confint[,"lwr"],
        temp78_rating_D$confint[,"lwr"],
        0,
        communitySuburban_rating_D$confint[,"lwr"],
        communityUrban_rating_D$confint[,"lwr"],
        0,
        attractionsBeaches_rating_D$confint[,"lwr"],
        attractionsMuseums_rating_D$confint[,"lwr"],
        attractionsParks_rating_D$confint[,"lwr"],
        attractionsSports_rating_D$confint[,"lwr"],
        attractionsTheaters_rating_D$confint[,"lwr"],
        0,
        traveltime2to4hours_rating_D$confint[,"lwr"],
        traveltime4to6hours_rating_D$confint[,"lwr"],
        traveltime6Plushours_rating_D$confint[,"lwr"],
        0,
        preselecSmallTrumpMargin_rating_D$confint[,"lwr"],
        preselecSmallBidenMargin_rating_D$confint[,"lwr"],
        preselecLargeBidenMargin_rating_D$confint[,"lwr"]),2)

# ACIE 95% upper bound
round(c(0,
        recentnewsExpandProtest_rating_D$confint[,"upr"],
        recentnewsExpandEarlyVoting_rating_D$confint[,"upr"],
        recentnewsLimitProtest_rating_D$confint[,"upr"],
        recentnewsLimitEarlyVoting_rating_D$confint[,"upr"],
        0,
        temp67_rating_D$confint[,"upr"],
        temp72_rating_D$confint[,"upr"],
        temp78_rating_D$confint[,"upr"],
        0,
        communitySuburban_rating_D$confint[,"upr"],
        communityUrban_rating_D$confint[,"upr"],
        0,
        attractionsBeaches_rating_D$confint[,"upr"],
        attractionsMuseums_rating_D$confint[,"upr"],
        attractionsParks_rating_D$confint[,"upr"],
        attractionsSports_rating_D$confint[,"upr"],
        attractionsTheaters_rating_D$confint[,"upr"],
        0,
        traveltime2to4hours_rating_D$confint[,"upr"],
        traveltime4to6hours_rating_D$confint[,"upr"],
        traveltime6Plushours_rating_D$confint[,"upr"],
        0,
        preselecSmallTrumpMargin_rating_D$confint[,"upr"],
        preselecSmallBidenMargin_rating_D$confint[,"upr"],
        preselecLargeBidenMargin_rating_D$confint[,"upr"]),2)

# among Republicans only

# ACIEs
round(c(0,
        recentnewsExpandProtest_rating_R$confint[,"Estimate"],
        recentnewsExpandEarlyVoting_rating_R$confint[,"Estimate"],
        recentnewsLimitProtest_rating_R$confint[,"Estimate"],
        recentnewsLimitEarlyVoting_rating_R$confint[,"Estimate"],
        0,
        temp67_rating_R$confint[,"Estimate"],
        temp72_rating_R$confint[,"Estimate"],
        temp78_rating_R$confint[,"Estimate"],
        0,
        communitySuburban_rating_R$confint[,"Estimate"],
        communityUrban_rating_R$confint[,"Estimate"],
        0,
        attractionsBeaches_rating_R$confint[,"Estimate"],
        attractionsMuseums_rating_R$confint[,"Estimate"],
        attractionsParks_rating_R$confint[,"Estimate"],
        attractionsSports_rating_R$confint[,"Estimate"],
        attractionsTheaters_rating_R$confint[,"Estimate"],
        0,
        traveltime2to4hours_rating_R$confint[,"Estimate"],
        traveltime4to6hours_rating_R$confint[,"Estimate"],
        traveltime6Plushours_rating_R$confint[,"Estimate"],
        0,
        preselecSmallTrumpMargin_rating_R$confint[,"Estimate"],
        preselecSmallBidenMargin_rating_R$confint[,"Estimate"],
        preselecLargeBidenMargin_rating_R$confint[,"Estimate"]),2)

# ACIE 95% lower bound
round(c(0,
        recentnewsExpandProtest_rating_R$confint[,"lwr"],
        recentnewsExpandEarlyVoting_rating_R$confint[,"lwr"],
        recentnewsLimitProtest_rating_R$confint[,"lwr"],
        recentnewsLimitEarlyVoting_rating_R$confint[,"lwr"],
        0,
        temp67_rating_R$confint[,"lwr"],
        temp72_rating_R$confint[,"lwr"],
        temp78_rating_R$confint[,"lwr"],
        0,
        communitySuburban_rating_R$confint[,"lwr"],
        communityUrban_rating_R$confint[,"lwr"],
        0,
        attractionsBeaches_rating_R$confint[,"lwr"],
        attractionsMuseums_rating_R$confint[,"lwr"],
        attractionsParks_rating_R$confint[,"lwr"],
        attractionsSports_rating_R$confint[,"lwr"],
        attractionsTheaters_rating_R$confint[,"lwr"],
        0,
        traveltime2to4hours_rating_R$confint[,"lwr"],
        traveltime4to6hours_rating_R$confint[,"lwr"],
        traveltime6Plushours_rating_R$confint[,"lwr"],
        0,
        preselecSmallTrumpMargin_rating_R$confint[,"lwr"],
        preselecSmallBidenMargin_rating_R$confint[,"lwr"],
        preselecLargeBidenMargin_rating_R$confint[,"lwr"]),2)

# 95% ACIE upper bound
round(c(0,
        recentnewsExpandProtest_rating_R$confint[,"upr"],
        recentnewsExpandEarlyVoting_rating_R$confint[,"upr"],
        recentnewsLimitProtest_rating_R$confint[,"upr"],
        recentnewsLimitEarlyVoting_rating_R$confint[,"upr"],
        0,
        temp67_rating_R$confint[,"upr"],
        temp72_rating_R$confint[,"upr"],
        temp78_rating_R$confint[,"upr"],
        0,
        communitySuburban_rating_R$confint[,"upr"],
        communityUrban_rating_R$confint[,"upr"],
        0,
        attractionsBeaches_rating_R$confint[,"upr"],
        attractionsMuseums_rating_R$confint[,"upr"],
        attractionsParks_rating_R$confint[,"upr"],
        attractionsSports_rating_R$confint[,"upr"],
        attractionsTheaters_rating_R$confint[,"upr"],
        0,
        traveltime2to4hours_rating_R$confint[,"upr"],
        traveltime4to6hours_rating_R$confint[,"upr"],
        traveltime6Plushours_rating_R$confint[,"upr"],
        0,
        preselecSmallTrumpMargin_rating_R$confint[,"upr"],
        preselecSmallBidenMargin_rating_R$confint[,"upr"],
        preselecLargeBidenMargin_rating_R$confint[,"upr"]),2)


# n for all respondents, # of all respondents
sum(table(study1_responses$rating, useNA = "always")[1:5])
length(unique(study1_responses$ResponseId[!is.na(study1_responses$rating)]))

# n for democrats, # of democrats
sum(table(study1_responses$rating[which(study1_responses$pid3=="D")], useNA = "always")[1:5])
length(unique(study1_responses$ResponseId[!is.na(study1_responses$rating) & study1_responses$pid3=="D"]))

# n for republicans, # of republicans
sum(table(study1_responses$rating[which(study1_responses$pid3=="R")], useNA = "always")[1:5])
length(unique(study1_responses$ResponseId[!is.na(study1_responses$rating) & study1_responses$pid3=="R"]))

# In addition to the tabular presentation, the text in Supplemental Information 
# Section SI.B1a makes mention of the comparisons of the non-baseline values of
# the ratings-based AMCEs/ACIEs for  recent state news. The code below uses glht
# to formally conduct the hypothesis tests discussed therein

# among all respondents, limit protest vs. expand protest
summary(glht(rating_model_crse, 
             linfct = "`recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` - `recentnewsState legislature enacted a law to expand the right to protest at the state capitol building` = 0"))

# among all respondents, expand protest vs. limit voting
summary(glht(rating_model_crse, 
             linfct = "`recentnewsState legislature enacted a law to expand the right to protest at the state capitol building` - `recentnewsState legislature enacted a law to limit voters ability to vote early in elections` = 0"))

# among all respondents, expand voting vs. limit voting
summary(glht(rating_model_crse, 
             linfct = "`recentnewsState legislature enacted a law to expand voters ability to vote early in elections` - `recentnewsState legislature enacted a law to limit voters ability to vote early in elections` = 0"))

# among all respondents, expand voting vs. limit protest
summary(glht(rating_model_crse, 
             linfct = "`recentnewsState legislature enacted a law to expand voters ability to vote early in elections` - `recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` = 0"))

# among Democratic respondents, limit protest vs. expand protest
summary(glht(rating_model_pid_crse, 
             linfct = "`recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` + `recentnewsState legislature enacted a law to limit the right to protest at the state capitol building:pid3D` - `recentnewsState legislature enacted a law to expand the right to protest at the state capitol building` - `recentnewsState legislature enacted a law to expand the right to protest at the state capitol building:pid3D` = 0"))

# among Democratic respondents, expand protest vs. limit voting
summary(glht(rating_model_pid_crse, 
             linfct = "`recentnewsState legislature enacted a law to expand the right to protest at the state capitol building` + `recentnewsState legislature enacted a law to expand the right to protest at the state capitol building:pid3D` - `recentnewsState legislature enacted a law to limit voters ability to vote early in elections` - `recentnewsState legislature enacted a law to limit voters ability to vote early in elections:pid3D` = 0"))

# among Democratic respondents, expand voting vs. limit voting
summary(glht(rating_model_pid_crse, 
             linfct = "`recentnewsState legislature enacted a law to expand voters ability to vote early in elections` + `recentnewsState legislature enacted a law to expand voters ability to vote early in elections:pid3D` - `recentnewsState legislature enacted a law to limit voters ability to vote early in elections` - `recentnewsState legislature enacted a law to limit voters ability to vote early in elections:pid3D` = 0"))

# among Democratic respondents, expand voting vs. limit protest
summary(glht(rating_model_pid_crse, 
             linfct = "`recentnewsState legislature enacted a law to expand voters ability to vote early in elections` + `recentnewsState legislature enacted a law to expand voters ability to vote early in elections:pid3D` - `recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` - `recentnewsState legislature enacted a law to limit the right to protest at the state capitol building:pid3D` = 0"))

# among Republican respondents, limit protest vs. expand protest
summary(glht(rating_model_pid_crse, 
             linfct = "`recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` - `recentnewsState legislature enacted a law to expand the right to protest at the state capitol building` = 0"))

# among Republican respondents, limit protest vs. limit voting
summary(glht(rating_model_pid_crse, 
             linfct = "`recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` - `recentnewsState legislature enacted a law to limit voters ability to vote early in elections` = 0"))

# among Republican respondents, expand protest vs. limit voting
summary(glht(rating_model_pid_crse, 
             linfct = "`recentnewsState legislature enacted a law to expand the right to protest at the state capitol building` - `recentnewsState legislature enacted a law to limit voters ability to vote early in elections` = 0"))

# among Republican respondents, expand voting vs. limit voting
summary(glht(rating_model_pid_crse, 
             linfct = "`recentnewsState legislature enacted a law to expand voters ability to vote early in elections` - `recentnewsState legislature enacted a law to limit voters ability to vote early in elections` = 0"))

# among Republican respondents, expand voting vs. limit protest
summary(glht(rating_model_pid_crse, 
             linfct = "`recentnewsState legislature enacted a law to expand voters ability to vote early in elections` - `recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` = 0"))

################################################################################

# TABLE SI.5

# first need to create weights

# every respondent has 30 observations (10 tasks x 3 profiles per task), so we
# subset such that we only have one observation per respondent; we will then
# merge the weights back to the study1_responses object
respondent_demos_weights <- subset(study1_responses, select = c("ResponseId", "pid3",
                                                                "gender", "income",
                                                                "age_bin_lucid", "educ",
                                                                "ideology", "raceeth_lucid",
                                                                "region"))

respondent_demos_weights <- respondent_demos_weights[!duplicated(respondent_demos_weights$ResponseId),]

# weights only calculated among respondents with non-missing values of relevant
# demos

respondent_demos_weights <- respondent_demos_weights[!(is.na(respondent_demos_weights$gender) | 
                                                       is.na(respondent_demos_weights$pid3) | 
                                                       is.na(respondent_demos_weights$income) | 
                                                       is.na(respondent_demos_weights$age_bin_lucid) | 
                                                       is.na(respondent_demos_weights$educ) | 
                                                       is.na(respondent_demos_weights$ideology) | 
                                                       is.na(respondent_demos_weights$raceeth_lucid) | 
                                                       is.na(respondent_demos_weights$region)),]

# the ACS bins income above $100k, so we need to do so with our income measure
# as well before using the survey package
respondent_demos_weights$income_acs <- ifelse(respondent_demos_weights$income>4, 5, respondent_demos_weights$income)

final_list_weights <- svydesign(ids=~1, data = respondent_demos_weights[which(!is.na(respondent_demos_weights$ResponseId)),])

# Lucid target weights on gender: 49% male, 51% female
gender.dist <- data.frame(gender = c("1", "2"),
                        Freq = nrow(final_list_weights) * c(0.49, 0.51))

# Lucid target weights on age: 13% 18-24, 20% 25-34, 20% 35-44, 33% 45-64, 14% 65-99
age.dist <- data.frame(age_bin_lucid = c("1", "2", "3", "4", "5"),
                              Freq = nrow(final_list_weights) * c(0.13, 0.20, 0.20, 0.33, 0.14))

# Lucid target weights on race/ethnicity: 68% white non-Hispanic, 12% black non-Hispanic, 10% Hispanic, 10% other
raceeth.dist <- data.frame(raceeth_lucid = c("1", "2", "3", "4"),
                       Freq = nrow(final_list_weights) * c(0.68, 0.12, 0.10, 0.10))

# Lucid target weights on region: 20% northeast, 20% midwest, 34% south, 26% west
region.dist <- data.frame(region = c("1", "2", "3", "4"),
                           Freq = nrow(final_list_weights) * c(0.20, 0.20, 0.34, 0.26))

# American Community Survey (2021, 1-year) estimates for education: 10.8% less 
# than HS education, 27.3% high school, 29.5% some college but no four-year degree,
# 20.2% four-year degree, 12.2% post-graduate degree
educ.dist <- data.frame(educ = c("1", "2", "3", "4", "5"),
                          Freq = nrow(final_list_weights) * c(0.108, 0.273, 0.295, 0.202, 0.122))

# American Community Survey (2021, 1-year) estimates for income: 11.7% less than $25k,
# 32.3% $25k-$49,999, 23.7% $50k to $74,999, 12.5% $75k to $99,999, 20.0% over $100k
income.dist <- data.frame(income_acs = c("1", "2", "3", "4", "5"),
                          Freq = nrow(final_list_weights) * c(0.117, 0.322, 0.237, 0.125, 0.200))

# ANES (2020) estimates for party ID (collapsing leaners into parties): 
# 45.7% Democrats, 40.6% Republicans, 10.5% Independents, 3.2% Other
pid.dist <- data.frame(pid3 = c("D", "R", "I", "O"),
                          Freq = nrow(final_list_weights) * c(0.457, 0.406, 0.105, 0.032))

# ANES (2020) estimates for ideology: 5.2% extreme liberal, 17.2% liberal, 13.0%
# slightly liberal, 25.8% moderate, 11.6% slightly conservative, 21.1% conservative,
# 6.1% extremely conservative
ideo.dist <- data.frame(ideology = c("1", "2", "3", "4", "5", "6", "7"),
                        Freq = nrow(final_list_weights) * c(0.052, 0.172, 0.130, 0.258, 0.116, 0.211, 0.061))

final_list_weights.rake <- rake(design = final_list_weights,
                                sample.margins = list(~gender, ~age_bin_lucid,
                                                      ~raceeth_lucid, ~region,
                                                      ~educ, ~income_acs,
                                                      ~pid3, ~ideology),
                                population.margins = list(gender.dist, age.dist,
                                                          raceeth.dist, region.dist,
                                                          educ.dist, income.dist,
                                                          pid.dist, ideo.dist))

# extracting respondent IDs and weights from rake object

survey_weights <- data.frame("respondent"=final_list_weights.rake$variables$ResponseId, 
                             "weight"=final_list_weights.rake$prob)

# merging weights back into original data frame

study1_responses <- merge(study1_responses, survey_weights, by.x="ResponseId", by.y = "respondent", all.x = TRUE)

# calculating weighted AMCEs among all respondents (choice outcome)
choice_model_weighted <- lm(choice ~ temp + attractions + traveltime + preselec + recentnews + community,
                   data = study1_responses, weights = weight)
# calculating variance-covariance matrix for cluster robust SEs (clustered on respondent)
choice_model_weighted_vcov <- cluster.vcov(choice_model, cluster = study1_responses$ResponseId)
# model summary with CRSEs
coeftest(choice_model_weighted, choice_model_weighted_vcov)
# saving SEs, p-values, and the variance-covariance matrix
choice_model_weighted_vcov_ses <- coeftest(choice_model_weighted, choice_model_weighted_vcov)[,2]
choice_model_weighted_vcov_pvals <- coeftest(choice_model_weighted, choice_model_weighted_vcov)[,4]
choice_model_weighted_crse <- withVCov(choice_model_weighted, choice_model_weighted_vcov)

# calculating weighted ACIEs among Democrats and Republicans (choice outcome)
# model conditions every non-baseline attribute level on PID (1 if Democrat, 0
# if Republican); ACIEs are then calculated from estimated coefficients using
# glht from the multcomp package (for Republicans, coefficients for 
# attribute-levels themselves are used; for Democrats, #the combination of the 
# coefficients from the attribute-levels themselves AND the corresponding terms 
# that interact PID and attribute-levels are used)
choice_model_weighted_pid <- lm(choice ~ temp + attractions + traveltime + 
                         preselec + recentnews + community + pid3 +
                         temp:pid3 + attractions:pid3 + traveltime:pid3 + 
                         preselec:pid3 + recentnews:pid3 + community:pid3,
                       data = study1_responses[which(study1_responses$pid3=="D" |
                                                       study1_responses$pid3=="R")],
                       weights = weight)
# calculating variance-covariance matrix for cluster robust SEs (clustered on respondent)
choice_model_weighted_pid_vcov <- cluster.vcov(choice_model_weighted_pid, 
                                      cluster = study1_responses$ResponseId[which(study1_responses$pid3=="D" |
                                                                                    study1_responses$pid3=="R")])
# model summary with CRSEs
coeftest(choice_model_weighted_pid, choice_model_weighted_pid_vcov)
# saving SEs, p-values, and the cariance-covariance matrix
choice_model_weighted_pid_vcov_ses <- coeftest(choice_model_weighted_pid, choice_model_weighted_pid_vcov)[,2]
choice_model_weighted_pid_vcov_pvals <- coeftest(choice_model_weighted_pid, choice_model_weighted_pid_vcov)[,4]
choice_model_weighted_pid_crse <- withVCov(choice_model_weighted_pid, choice_model_weighted_pid_vcov)

# obtaining calculating weighted ACIEs and corresponding 95% confidence intervals for each
# non-baseline attribute-level among Democrats and Republicans as descriibed above
# (object names indicate which ACIEs are stored therein)

# ACIEs for Democrats
temp67_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                linfct = "temp67 + temp67:pid3D = 0"))
temp72_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                linfct = "temp72 + temp72:pid3D = 0"))
temp78_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                linfct = "temp78 + temp78:pid3D = 0"))
communitySuburban_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                           linfct = "communitySuburban + communitySuburban:pid3D = 0"))
communityUrban_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                        linfct = "communityUrban + communityUrban:pid3D = 0"))
attractionsBeaches_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                            linfct = "attractionsBeaches + attractionsBeaches:pid3D = 0"))
attractionsMuseums_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                            linfct = "attractionsMuseums + attractionsMuseums:pid3D = 0"))
attractionsParks_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                          linfct = "`attractionsNational parks` + `attractionsNational parks:pid3D` = 0"))
attractionsSports_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                           linfct = "`attractionsSporting events` + `attractionsSporting events:pid3D` = 0"))
attractionsTheaters_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                             linfct = "attractionsTheaters + attractionsTheaters:pid3D = 0"))
traveltime2to4hours_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                             linfct = "`traveltime2-4 hours` + `traveltime2-4 hours:pid3D` = 0"))
traveltime4to6hours_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                             linfct = "`traveltime4-6 hours` + `traveltime4-6 hours:pid3D` = 0"))
traveltime6Plushours_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                              linfct = "`traveltimeMore than 6 hours` + `traveltimeMore than 6 hours:pid3D` = 0"))
preselecSmallTrumpMargin_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                                  linfct = "`preselecDonald Trump won by a small margin` + `preselecDonald Trump won by a small margin:pid3D` = 0"))
preselecSmallBidenMargin_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                                  linfct = "`preselecJoe Biden won by a small margin` + `preselecJoe Biden won by a small margin:pid3D` = 0"))
preselecLargeBidenMargin_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                                  linfct = "`preselecJoe Biden won by a large margin` + `preselecJoe Biden won by a large margin:pid3D` = 0"))
recentnewsExpandProtest_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                                 linfct = "`recentnewsState legislature enacted a law to expand the right to protest at the state capitol building` + `recentnewsState legislature enacted a law to expand the right to protest at the state capitol building:pid3D` = 0"))
recentnewsExpandEarlyVoting_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                                     linfct = "`recentnewsState legislature enacted a law to expand voters ability to vote early in elections` + `recentnewsState legislature enacted a law to expand voters ability to vote early in elections:pid3D` = 0"))
recentnewsLimitProtest_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                                linfct = "`recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` + `recentnewsState legislature enacted a law to limit the right to protest at the state capitol building:pid3D` = 0"))
recentnewsLimitEarlyVoting_choice_weighted_D <- confint(glht(choice_model_weighted_pid_crse, 
                                                    linfct = "`recentnewsState legislature enacted a law to limit voters ability to vote early in elections` + `recentnewsState legislature enacted a law to limit voters ability to vote early in elections:pid3D` = 0"))

# ACIEs for Republicans
temp67_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                linfct = "temp67 = 0"))
temp72_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                linfct = "temp72 = 0"))
temp78_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                linfct = "temp78 = 0"))
communitySuburban_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                           linfct = "communitySuburban = 0"))
communityUrban_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                        linfct = "communityUrban = 0"))
attractionsBeaches_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                            linfct = "attractionsBeaches = 0"))
attractionsMuseums_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                            linfct = "attractionsMuseums = 0"))
attractionsParks_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                          linfct = "`attractionsNational parks` = 0"))
attractionsSports_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                           linfct = "`attractionsSporting events` = 0"))
attractionsTheaters_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                             linfct = "attractionsTheaters = 0"))
traveltime2to4hours_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                             linfct = "`traveltime2-4 hours` = 0"))
traveltime4to6hours_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                             linfct = "`traveltime4-6 hours` = 0"))
traveltime6Plushours_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                              linfct = "`traveltimeMore than 6 hours` = 0"))
preselecSmallTrumpMargin_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                                  linfct = "`preselecDonald Trump won by a small margin` = 0"))
preselecSmallBidenMargin_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                                  linfct = "`preselecJoe Biden won by a small margin` = 0"))
preselecLargeBidenMargin_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                                  linfct = "`preselecJoe Biden won by a large margin` = 0"))
recentnewsExpandProtest_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                                 linfct = "`recentnewsState legislature enacted a law to expand the right to protest at the state capitol building` = 0"))
recentnewsExpandEarlyVoting_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                                     linfct = "`recentnewsState legislature enacted a law to expand voters ability to vote early in elections` = 0"))
recentnewsLimitProtest_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                                linfct = "`recentnewsState legislature enacted a law to limit the right to protest at the state capitol building` = 0"))
recentnewsLimitEarlyVoting_choice_weighted_R <- confint(glht(choice_model_weighted_pid_crse, 
                                                    linfct = "`recentnewsState legislature enacted a law to limit voters ability to vote early in elections`= 0"))

# obtaining values for Table SI.5

# among all respondents
# AMCEs
round(c(0,
        choice_model_weighted_crse$coefficients["recentnewsState legislature enacted a law to expand the right to protest at the state capitol building"],
        choice_model_weighted_crse$coefficients["recentnewsState legislature enacted a law to expand voters ability to vote early in elections"],
        choice_model_weighted_crse$coefficients["recentnewsState legislature enacted a law to limit the right to protest at the state capitol building"],
        choice_model_weighted_crse$coefficients["recentnewsState legislature enacted a law to limit voters ability to vote early in elections"],
        0,
        choice_model_weighted_crse$coefficients["temp67"],
        choice_model_weighted_crse$coefficients["temp72"],
        choice_model_weighted_crse$coefficients["temp78"],
        0,
        choice_model_weighted_crse$coefficients["communitySuburban"],
        choice_model_weighted_crse$coefficients["communityUrban"],
        0,
        choice_model_weighted_crse$coefficients["attractionsBeaches"],
        choice_model_weighted_crse$coefficients["attractionsMuseums"],
        choice_model_weighted_crse$coefficients["attractionsNational parks"],
        choice_model_weighted_crse$coefficients["attractionsSporting events"],
        choice_model_weighted_crse$coefficients["attractionsTheaters"],
        0,
        choice_model_weighted_crse$coefficients["traveltime2-4 hours"],
        choice_model_weighted_crse$coefficients["traveltime4-6 hours"],
        choice_model_weighted_crse$coefficients["traveltimeMore than 6 hours"],
        0,
        choice_model_weighted_crse$coefficients["preselecDonald Trump won by a small margin"],
        choice_model_weighted_crse$coefficients["preselecJoe Biden won by a small margin"],
        choice_model_weighted_crse$coefficients["preselecJoe Biden won by a large margin"]),2)
# AMCE 95% lower bound
round(c(0,
        confint(choice_model_weighted_crse)["recentnewsState legislature enacted a law to expand the right to protest at the state capitol building",1],
        confint(choice_model_weighted_crse)["recentnewsState legislature enacted a law to expand voters ability to vote early in elections",1],
        confint(choice_model_weighted_crse)["recentnewsState legislature enacted a law to limit the right to protest at the state capitol building",1],
        confint(choice_model_weighted_crse)["recentnewsState legislature enacted a law to limit voters ability to vote early in elections",1],
        0,
        confint(choice_model_weighted_crse)["temp67",1],
        confint(choice_model_weighted_crse)["temp72",1],
        confint(choice_model_weighted_crse)["temp78",1],
        0,
        confint(choice_model_weighted_crse)["communitySuburban",1],
        confint(choice_model_weighted_crse)["communityUrban",1],
        0,
        confint(choice_model_weighted_crse)["attractionsBeaches",1],
        confint(choice_model_weighted_crse)["attractionsMuseums",1],
        confint(choice_model_weighted_crse)["attractionsNational parks",1],
        confint(choice_model_weighted_crse)["attractionsSporting events",1],
        confint(choice_model_weighted_crse)["attractionsTheaters",1],
        0,
        confint(choice_model_weighted_crse)["traveltime2-4 hours",1],
        confint(choice_model_weighted_crse)["traveltime4-6 hours",1],
        confint(choice_model_weighted_crse)["traveltimeMore than 6 hours",1],
        0,
        confint(choice_model_weighted_crse)["preselecDonald Trump won by a small margin",1],
        confint(choice_model_weighted_crse)["preselecJoe Biden won by a small margin",1],
        confint(choice_model_weighted_crse)["preselecJoe Biden won by a large margin",1]),2)
# AMCE 95% upper bound
round(c(0,
        confint(choice_model_weighted_crse)["recentnewsState legislature enacted a law to expand the right to protest at the state capitol building",2],
        confint(choice_model_weighted_crse)["recentnewsState legislature enacted a law to expand voters ability to vote early in elections",2],
        confint(choice_model_weighted_crse)["recentnewsState legislature enacted a law to limit the right to protest at the state capitol building",2],
        confint(choice_model_weighted_crse)["recentnewsState legislature enacted a law to limit voters ability to vote early in elections",2],
        0,
        confint(choice_model_weighted_crse)["temp67",2],
        confint(choice_model_weighted_crse)["temp72",2],
        confint(choice_model_weighted_crse)["temp78",2],
        0,
        confint(choice_model_weighted_crse)["communitySuburban",2],
        confint(choice_model_weighted_crse)["communityUrban",2],
        0,
        confint(choice_model_weighted_crse)["attractionsBeaches",2],
        confint(choice_model_weighted_crse)["attractionsMuseums",2],
        confint(choice_model_weighted_crse)["attractionsNational parks",2],
        confint(choice_model_weighted_crse)["attractionsSporting events",2],
        confint(choice_model_weighted_crse)["attractionsTheaters",2],
        0,
        confint(choice_model_weighted_crse)["traveltime2-4 hours",2],
        confint(choice_model_weighted_crse)["traveltime4-6 hours",2],
        confint(choice_model_weighted_crse)["traveltimeMore than 6 hours",2],
        0,
        confint(choice_model_weighted_crse)["preselecDonald Trump won by a small margin",2],
        confint(choice_model_weighted_crse)["preselecJoe Biden won by a small margin",2],
        confint(choice_model_weighted_crse)["preselecJoe Biden won by a large margin",2]),2)

# among Democrats only

# ACIEs
round(c(0,
        recentnewsExpandProtest_choice_weighted_D$confint[,"Estimate"],
        recentnewsExpandEarlyVoting_choice_weighted_D$confint[,"Estimate"],
        recentnewsLimitProtest_choice_weighted_D$confint[,"Estimate"],
        recentnewsLimitEarlyVoting_choice_weighted_D$confint[,"Estimate"],
        0,
        temp67_choice_weighted_D$confint[,"Estimate"],
        temp72_choice_weighted_D$confint[,"Estimate"],
        temp78_choice_weighted_D$confint[,"Estimate"],
        0,
        communitySuburban_choice_weighted_D$confint[,"Estimate"],
        communityUrban_choice_weighted_D$confint[,"Estimate"],
        0,
        attractionsBeaches_choice_weighted_D$confint[,"Estimate"],
        attractionsMuseums_choice_weighted_D$confint[,"Estimate"],
        attractionsParks_choice_weighted_D$confint[,"Estimate"],
        attractionsSports_choice_weighted_D$confint[,"Estimate"],
        attractionsTheaters_choice_weighted_D$confint[,"Estimate"],
        0,
        traveltime2to4hours_choice_weighted_D$confint[,"Estimate"],
        traveltime4to6hours_choice_weighted_D$confint[,"Estimate"],
        traveltime6Plushours_choice_weighted_D$confint[,"Estimate"],
        0,
        preselecSmallTrumpMargin_choice_weighted_D$confint[,"Estimate"],
        preselecSmallBidenMargin_choice_weighted_D$confint[,"Estimate"],
        preselecLargeBidenMargin_choice_weighted_D$confint[,"Estimate"]),2)

# ACIE 95% lower bound
round(c(0,
        recentnewsExpandProtest_choice_weighted_D$confint[,"lwr"],
        recentnewsExpandEarlyVoting_choice_weighted_D$confint[,"lwr"],
        recentnewsLimitProtest_choice_weighted_D$confint[,"lwr"],
        recentnewsLimitEarlyVoting_choice_weighted_D$confint[,"lwr"],
        0,
        temp67_choice_weighted_D$confint[,"lwr"],
        temp72_choice_weighted_D$confint[,"lwr"],
        temp78_choice_weighted_D$confint[,"lwr"],
        0,
        communitySuburban_choice_weighted_D$confint[,"lwr"],
        communityUrban_choice_weighted_D$confint[,"lwr"],
        0,
        attractionsBeaches_choice_weighted_D$confint[,"lwr"],
        attractionsMuseums_choice_weighted_D$confint[,"lwr"],
        attractionsParks_choice_weighted_D$confint[,"lwr"],
        attractionsSports_choice_weighted_D$confint[,"lwr"],
        attractionsTheaters_choice_weighted_D$confint[,"lwr"],
        0,
        traveltime2to4hours_choice_weighted_D$confint[,"lwr"],
        traveltime4to6hours_choice_weighted_D$confint[,"lwr"],
        traveltime6Plushours_choice_weighted_D$confint[,"lwr"],
        0,
        preselecSmallTrumpMargin_choice_weighted_D$confint[,"lwr"],
        preselecSmallBidenMargin_choice_weighted_D$confint[,"lwr"],
        preselecLargeBidenMargin_choice_weighted_D$confint[,"lwr"]),2)

# ACIE 95% upper bound
round(c(0,
        recentnewsExpandProtest_choice_weighted_D$confint[,"upr"],
        recentnewsExpandEarlyVoting_choice_weighted_D$confint[,"upr"],
        recentnewsLimitProtest_choice_weighted_D$confint[,"upr"],
        recentnewsLimitEarlyVoting_choice_weighted_D$confint[,"upr"],
        0,
        temp67_choice_weighted_D$confint[,"upr"],
        temp72_choice_weighted_D$confint[,"upr"],
        temp78_choice_weighted_D$confint[,"upr"],
        0,
        communitySuburban_choice_weighted_D$confint[,"upr"],
        communityUrban_choice_weighted_D$confint[,"upr"],
        0,
        attractionsBeaches_choice_weighted_D$confint[,"upr"],
        attractionsMuseums_choice_weighted_D$confint[,"upr"],
        attractionsParks_choice_weighted_D$confint[,"upr"],
        attractionsSports_choice_weighted_D$confint[,"upr"],
        attractionsTheaters_choice_weighted_D$confint[,"upr"],
        0,
        traveltime2to4hours_choice_weighted_D$confint[,"upr"],
        traveltime4to6hours_choice_weighted_D$confint[,"upr"],
        traveltime6Plushours_choice_weighted_D$confint[,"upr"],
        0,
        preselecSmallTrumpMargin_choice_weighted_D$confint[,"upr"],
        preselecSmallBidenMargin_choice_weighted_D$confint[,"upr"],
        preselecLargeBidenMargin_choice_weighted_D$confint[,"upr"]),2)

# among Republicans only

# ACIEs
round(c(0,
        recentnewsExpandProtest_choice_weighted_R$confint[,"Estimate"],
        recentnewsExpandEarlyVoting_choice_weighted_R$confint[,"Estimate"],
        recentnewsLimitProtest_choice_weighted_R$confint[,"Estimate"],
        recentnewsLimitEarlyVoting_choice_weighted_R$confint[,"Estimate"],
        0,
        temp67_choice_weighted_R$confint[,"Estimate"],
        temp72_choice_weighted_R$confint[,"Estimate"],
        temp78_choice_weighted_R$confint[,"Estimate"],
        0,
        communitySuburban_choice_weighted_R$confint[,"Estimate"],
        communityUrban_choice_weighted_R$confint[,"Estimate"],
        0,
        attractionsBeaches_choice_weighted_R$confint[,"Estimate"],
        attractionsMuseums_choice_weighted_R$confint[,"Estimate"],
        attractionsParks_choice_weighted_R$confint[,"Estimate"],
        attractionsSports_choice_weighted_R$confint[,"Estimate"],
        attractionsTheaters_choice_weighted_R$confint[,"Estimate"],
        0,
        traveltime2to4hours_choice_weighted_R$confint[,"Estimate"],
        traveltime4to6hours_choice_weighted_R$confint[,"Estimate"],
        traveltime6Plushours_choice_weighted_R$confint[,"Estimate"],
        0,
        preselecSmallTrumpMargin_choice_weighted_R$confint[,"Estimate"],
        preselecSmallBidenMargin_choice_weighted_R$confint[,"Estimate"],
        preselecLargeBidenMargin_choice_weighted_R$confint[,"Estimate"]),2)

# ACIE 95% lower bound
round(c(0,
        recentnewsExpandProtest_choice_weighted_R$confint[,"lwr"],
        recentnewsExpandEarlyVoting_choice_weighted_R$confint[,"lwr"],
        recentnewsLimitProtest_choice_weighted_R$confint[,"lwr"],
        recentnewsLimitEarlyVoting_choice_weighted_R$confint[,"lwr"],
        0,
        temp67_choice_weighted_R$confint[,"lwr"],
        temp72_choice_weighted_R$confint[,"lwr"],
        temp78_choice_weighted_R$confint[,"lwr"],
        0,
        communitySuburban_choice_weighted_R$confint[,"lwr"],
        communityUrban_choice_weighted_R$confint[,"lwr"],
        0,
        attractionsBeaches_choice_weighted_R$confint[,"lwr"],
        attractionsMuseums_choice_weighted_R$confint[,"lwr"],
        attractionsParks_choice_weighted_R$confint[,"lwr"],
        attractionsSports_choice_weighted_R$confint[,"lwr"],
        attractionsTheaters_choice_weighted_R$confint[,"lwr"],
        0,
        traveltime2to4hours_choice_weighted_R$confint[,"lwr"],
        traveltime4to6hours_choice_weighted_R$confint[,"lwr"],
        traveltime6Plushours_choice_weighted_R$confint[,"lwr"],
        0,
        preselecSmallTrumpMargin_choice_weighted_R$confint[,"lwr"],
        preselecSmallBidenMargin_choice_weighted_R$confint[,"lwr"],
        preselecLargeBidenMargin_choice_weighted_R$confint[,"lwr"]),2)

# 95% ACIE upper bound
round(c(0,
        recentnewsExpandProtest_choice_weighted_R$confint[,"upr"],
        recentnewsExpandEarlyVoting_choice_weighted_R$confint[,"upr"],
        recentnewsLimitProtest_choice_weighted_R$confint[,"upr"],
        recentnewsLimitEarlyVoting_choice_weighted_R$confint[,"upr"],
        0,
        temp67_choice_weighted_R$confint[,"upr"],
        temp72_choice_weighted_R$confint[,"upr"],
        temp78_choice_weighted_R$confint[,"upr"],
        0,
        communitySuburban_choice_weighted_R$confint[,"upr"],
        communityUrban_choice_weighted_R$confint[,"upr"],
        0,
        attractionsBeaches_choice_weighted_R$confint[,"upr"],
        attractionsMuseums_choice_weighted_R$confint[,"upr"],
        attractionsParks_choice_weighted_R$confint[,"upr"],
        attractionsSports_choice_weighted_R$confint[,"upr"],
        attractionsTheaters_choice_weighted_R$confint[,"upr"],
        0,
        traveltime2to4hours_choice_weighted_R$confint[,"upr"],
        traveltime4to6hours_choice_weighted_R$confint[,"upr"],
        traveltime6Plushours_choice_weighted_R$confint[,"upr"],
        0,
        preselecSmallTrumpMargin_choice_weighted_R$confint[,"upr"],
        preselecSmallBidenMargin_choice_weighted_R$confint[,"upr"],
        preselecLargeBidenMargin_choice_weighted_R$confint[,"upr"]),2)

# n for all respondents, # of all respondents
sum(table(study1_responses$choice[!is.na(study1_responses$weight)], useNA = "always")[1:2])
length(unique(study1_responses$ResponseId[!is.na(study1_responses$choice) & !is.na(study1_responses$weight)]))

# n for democrats, # of democrats
sum(table(study1_responses$choice[which(study1_responses$pid3=="D" & !is.na(study1_responses$weight))], useNA = "always")[1:2])
length(unique(study1_responses$ResponseId[!is.na(study1_responses$choice) & !is.na(study1_responses$weight) & study1_responses$pid3=="D"]))

# n for republicans, # of republicans
sum(table(study1_responses$choice[which(study1_responses$pid3=="R" & !is.na(study1_responses$weight))], useNA = "always")[1:2])
length(unique(study1_responses$ResponseId[!is.na(study1_responses$choice) & !is.na(study1_responses$weight) & study1_responses$pid3=="R"]))